我对单选按钮有疑问。我在字段集中有 2 组单选按钮和一个命令按钮。基于单选按钮的选择,将通过 ajax 调用显示受尊重的值。但问题总是第一个按钮在命令按钮操作中得到考虑,这就是为什么总是显示第一个值,但是选择了第二个单选按钮。这是我的代码
//test.xhtml
<h:panelGroup id="demandDashBoardPanelGroupID">
<fieldset>
<legend style="font-family:Arial;font-size: 12px;">Demand Dashboard</legend>
<table>
<tr>
<td>
<h:selectOneRadio immediate="true" id="groupbyid" value="#{demandManagedBean.selectedRadioButton}" styleClass="labelstyle">
<f:selectItem itemLabel="Group By Creation Date Time" itemValue="1" />
<f:selectItem itemLabel="Group By Location" itemValue="2" />
</h:selectOneRadio>
</td>
<td>
<h:commandButton id="fetchbuttonID" value="Fetch"
style="font-size:13px;width:60px;height:25px;" action="#{demandManagedBean.displayDemandRequestsTable}">
<f:setPropertyActionListener target="#{demandManagedBean.selectedRadioButtonParam}" value="#{demandManagedBean.selectedRadioButton}"/>
<f:ajax render=":parentformid:demandrequestpanelgrpid" immediate="true"/>
</h:commandButton>
</td>
</tr>
</table>
</fieldset>
</h:panelGroup>
<h:panelGroup id="demandrequestpanelgrpid" rendered="#{demandManagedBean.renderedFieldSet}">
<fieldset id="demandrequestfieldsetid">
<legend style="font-family:Arial;font-size: 12px;">Demand Requests</legend>
<h:outputText rendered="#{demandManagedBean.renderCreationdateDmdtable}" value="first table"/>
<h:outputText rendered="#{demandManagedBean.renderDmdLocationTable}" value="second table"/>
</fieldset>
</h:panelGroup>
//支持bean动作
public void displayDemandRequestsTable(){
if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("1")){
renderCreationdateDmdtable = true;
renderDmdLocationTable = false;
}else if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("2")){
renderCreationdateDmdtable = false;
renderDmdLocationTable = true;
}
renderedFieldSet = true;
}