我知道这个问题很简单,但我找到的所有答案都涉及到使用javascript,我想知道是否有更好的方法。
我想禁用确认按钮,直到上面的复选框被勾选,我该怎么做,然后如果它被勾选和取消勾选,它就会返回到禁用
<p:selectBooleanCheckbox id="Markconfirm"
value="#{markingBean.markToEdit.markingCompleted}"/>
</p:panelGrid>
<p:button id="back"
value="back"
outcome="/cohort-coordinator/marking/view-all-marks"
icon="ui-icon-arrowthickstop-1-w"/>
<p:commandButton id="confirm"
value="Confirm"
actionListener ="#{markingBean.editMark}"
update=":growl"
icon="ui-icon-disk"/>
将禁用或启用boutton的ajax事件添加到您的复选框中。
<p:selectBooleanCheckbox id="Markconfirm" value="#{markingBean.markToEdit.markingCompleted}">
<p:ajax event="change" update="confirm" />
</p:selectBooleanCheckbox>
<p:commandButton id="confirm"
value="Confirm"
disabled="#{markingBean.markToEdit.markingCompleted}"
actionListener ="#{markingBean.editMark}"
update=":growl"
icon="ui-icon-disk"/>
通过Javascript执行以下操作:在<p:commandButton>
中添加一个小部件Var,我们称之为confirmButtonWV
<p:commandButton widgetVar="confirmButtonWV" disabled="true" id="confirm" value="Confirm" actionListener ="#{markingBean.editMark}" update=":growl" icon="ui-icon-disk"/>
和一个用于复选框的小工具Var,我们称之为markConfirmWV
:
<p:selectBooleanCheckbox widgetVar="markConfirmWV" id="Markconfirm" value="#{markingBean.markToEdit.markingCompleted}" />
然后使用下一个脚本:
<script>
$(document).ready(function() {
markConfirmWV.jq.on('click', function() {
var confirmButton = confirmButtonWV.jq;
if (confirmButton.is(":disabled")) {
confirmButton.removeAttr('disabled').removeClass('ui-state-disabled');
} else {
confirmButton.attr('disabled', 'disabled').addClass('ui-state-disabled');
}
});
});
</script>