我使用 h:selectOneRadio 并在尝试更改默认收音机选择时遇到问题。下面是JSF代码
<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>
下面是 selectedRecurrenceValue 的 backingbean 代码
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;
}
当我尝试更改 radioselection 选项时会出现此问题。我无法初始化值 selectedRecurrenceValue,因为我动态获取它。当我尝试选择另一个单选按钮时,我收到 selectedRecurrenceValue 的空指针异常。任何解决该问题的指示都会非常有帮助。在此先感谢。