gpt4 book ai didi

java - JSF SelectOneRadio 按钮无法禁用

转载 作者:行者123 更新时间:2023-12-01 15:46:04 25 4
gpt4 key购买 nike

我有两个单选按钮,它们由 JSF 中 Backed bean 的两个实例变量支持{这是要求,而不是与一个变量绑定(bind)。}。并且,如果选中一项,则应禁用另一项。下面是我的代码,有什么问题吗?为什么它没有按我的预期工作。

感谢适当的帮助。

    <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>

最佳答案

单选按钮未相互连接。

您可以做的就是仅绑定(bind)一个并使用脚本取消选择另一个。在您的 bean 中执行相同操作,当 boolean 值 a 设置为 true 时,将 b 设置为 false ,反之亦然。

关于java - JSF SelectOneRadio 按钮无法禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com