我有两个单选按钮,它们由JSF中一个backing bean的两个实例变量支持{这是要求,而不是绑定一个变量}。如果一个被选中,另一个应该被禁用。下面是我的代码,有什么问题吗?为什么它不像我预期的那样工作
感谢您的帮助。
<h:graphicImage url="/images/orange_arrows.gif" />
<h:outputLabel for="addBundle">
<h:outputText value="Subscribe Bundle :" styleClass="item-name"/>
</h:outputLabel>
<h:selectOneRadio id="addBundle" value="#{accountAdjustmentBean.bundleAdded}" required="false"
onchange="enableSubmit( this.checked != bundleAdded );disableRadioButton('unsubscribe');">
<f:selectItem id="subscribe" itemValue="true"/>
<h:message styleClass="errors" for="addBundle"/>
</h:selectOneRadio>
<h:panelGroup/>
<h:graphicImage url="/images/orange_arrows.gif" />
<h:outputLabel for="removeBundle">
<h:outputText value="Unsubscribe Bundle" styleClass="item-name"/>
</h:outputLabel>
<h:selectOneRadio id="removeBundle" value="#{accountAdjustmentBean.bundleRemoved}" required="false"
onchange="enableSubmit( this.checked != bundleRemoved );disableRadioButton('subscribe');">
<f:selectItem id="unsubscribe" itemValue="true"/>
<h:message styleClass="errors" for="removeBundle"/>
</h:selectOneRadio>
<h:panelGrid columns="1" styleClass="adjustments-submit">
<h:commandButton id="submitBtn" action="#{accountAdjustmentBean.addDataBundleAction}"
value="Submit"/>
<f:verbatim>
<script type="text/javascript">
function enableSubmit( enable ) {
document.getElementById('ccAcountStatus:submitBtn').disabled = !enable;
}
// Disable submit button on load (enable when account locked status changes)
enableSubmit(false);
function disableRadioButton(elementId) {
document.getElementById(elementId).disabled = true;
}
// save the account locked status at page load. used to detect if changed.
var bundleadded = </f:verbatim><h:outputText value="#{accountAdjustmentBean.bundleAdded}"/><f:verbatim>
</script>
</f:verbatim>
单选按钮没有相互连接。
你可以做的是只绑定一个,并使用脚本取消选择另一个。在bean中做同样的事情,当布尔值a被设置为true时,将b设置为false,反之亦然。