Im using the h:selectOneRadio and having issues when I try to change the default radio selection. Below is the JSF code
<h:selectOneRadio id="radioSelectID1" layout="pageDirection" value="#{scheduleBean.selectedRecurrenceValue}" immediate="true" >
<f:selectItem id="dailyID" itemLabel="#{adminBean.adminScreenLabelVO.dailyLabel}" itemValue="#{scheduleBean.dailyValue}"></f:selectItem>
<f:selectItem id="weeklyID" itemLabel="#{adminBean.adminScreenLabelVO.weeklyLabel}" itemValue="#{scheduleBean.weeklyValue}"></f:selectItem>
<f:selectItem id="monthlyID" itemLabel="#{adminBean.adminScreenLabelVO.monthlyLabel}" itemValue="#{scheduleBean.monthlyValue}"></f:selectItem>
<f:ajax event="change" listener="#{scheduleBean.recurrenceChange}" render="recurrencePanelID" />
</h:selectOneRadio>
below is the backingbean code for the selectedRecurrenceValue
public String getSelectedRecurrenceValue() {
if(selectedRecurrenceValue == null)
{
selectedRecurrenceValue = adminScheduledetailsVO.getFrequency();
if(selectedRecurrenceValue.equalsIgnoreCase(dailyValue))
{
dailyPanelRenderer = true ;
}
if(selectedRecurrenceValue.equalsIgnoreCase(weeklyValue))
{
dailyPanelRenderer = false ;
weeklyPanelRenderer = true ;
}
if(selectedRecurrenceValue.equalsIgnoreCase(monthlyValue))
{
monthlyPanelRenderer = true ;
}
}
return selectedRecurrenceValue;
}
The issue occurs when I try to change the radioselection option. Im unable to initialize the value selectedRecurrenceValue, since Im getting it dynamically. When I try to select another radio button, Im receiving a null pointer exception for selectedRecurrenceValue.
Any pointers to fix the issue would be really helpful.Thanks in Advance.
If I read your question right it seems that you don’t need the field
selectedRecurrenceValueand should bindadminScheduledetailsVO.frequencydirectly to your selectOneRadio:Then of course
adminScheduledetailsVOneeds to be initialized before to avoid the NPE.