I have bound a p:selectOneRadio component as below,
<p:selectOneRadio binding="#{bean.maritalStatusRadio}" value="#{bean.maritalStatus}" >
<f:selectItems value="#{selectItemList.maritalStatusList}" />
<p:ajax event="change" listener="#{bean.handleChangeInMaritalStatus}" />
</p:selectOneRadio>
But I am unable to update its value from backing bean class.
SelectOneRadio maritalStatusRadio;
public void handleChangeInMaritalStatus() {
String currentValue =String.valueOf(maritalStatusRadio.getValue());
if(!currentValue.equals(MARITAL_STATUS_MARRIED)) {
maritalStatusRadio.setValue(MARITAL_STATUS_MARRIED);
}
}`
Your listener method is not the place to change your select value. It's for doing whatever you need when the user changes selected option in the view.
If you want to change the value selected you simply need to change the value assigned to your bound field, in this case bean.maritalStatus. You can do it in many places (including youtr listener if required).
Usually on preRenderView method is the place to initialize a select default value. On your view:
On your bean: