I writing JSF page, which requires users to click on a checkbox (similar to accepting the license agreement) I have following code in place:
<h:selectBooleanCheckbox value="#{checkBoxManagedBean.checkBoxValue}" required="true" id="jsfcheckBox" >
</h:selectBooleanCheckbox>
<h:outputLabel value="accept rule label" for="jsfcheckBox" />
<h:message for="jsfcheckBox"/>
<br/>
<h:commandButton id="loginButton" value="Submit"
action="#{checkBoxManagedBean.testAction}"/>
I am setting the required=true, but there is no validation happening for checkbox. I dont see any message getting displayed in the page for checkbox.
I have tried f:validateRequired, even this is not working.
<h:selectBooleanCheckbox value="#{checkBoxManagedBean.checkBoxValue}" required="true" id="jsfcheckBox" >
<f:validateRequired for="jsfcheckBox"></f:validateRequired>
</h:selectBooleanCheckbox>
<h:outputLabel value="CheckBox label" for="jsfcheckBox" />
<h:message for="jsfcheckBox"/>
<br/>
<h:commandButton id="loginButton" value="Submit"
action="#{checkBoxManagedBean.testAction}"/>
The page doesnt have any time issue, checkbox, buttons everything visible, my expectation is getting a validation message, when checkbox is not selected before button is pressed.
BTW, is it JSF specification that required=true doesn't really execute any validation??
required=true
for jsf input fields means that the value of the field must not be empty or null. This seems like bug in jsf implementation, but when h:selectBooleanCheckbox
is not checked, it's value is false
and not empty or null
. So this does not trigger the validation. BalusC has written a nice post about this here. He implemented a validator for this that helps you overcome the situation. Thanks BalusC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With