Class RequiredCheckboxValidator
- java.lang.Object
-
- org.omnifaces.validator.RequiredCheckboxValidator
-
- All Implemented Interfaces:
Validator<Boolean>
,EventListener
public class RequiredCheckboxValidator extends Object implements Validator<Boolean>
The
omnifaces.RequiredCheckboxValidator
is intented to solve a peculiar problem withrequired="true"
attribute ofUISelectBoolean
components like<h:selectBooleanCheckbox>
. If you want to require the user to tick the desired checkbox, you would expect that settingrequired="true"
is sufficient. But it is not, the validation wil always pass.As for every other
UIInput
component the defaultrequired="true"
validator would only check if the value is actually filled and been sent to the server side, i.e. the value is not null nor empty. In case of a<h:selectBooleanCheckbox>
, which acceptsBoolean
orboolean
properties only, EL will coerce the unchecked value toBoolean.FALSE
during apply request values phase right before validations phase. This value is notnull
nor empty! Thus, the required attribute of the<h:selectBooleanCheckbox>
is fairly pointless. It would always pass the validation and thus never display the desired required message in case of an unticked checkbox.Usage
This validator is available by validator ID
omnifaces.RequiredCheckboxValidator
. Just specify it as<f:validator>
of the boolean selection component:<h:selectBooleanCheckbox id="agree" value="#{bean.agree}" requiredMessage="You must agree!"> <f:validator validatorId="omnifaces.RequiredCheckboxValidator" /> </h:selectBooleanCheckbox>
The validator will use the message as specified in
requiredMessage
. If it's absent, then it will use the default required message as specified in custom<message-bundle>
infaces-config.xml
. If it's absent, then it will default to{0}: a tick is required"
- Author:
- Bauke Scholtz
-
-
Field Summary
-
Fields inherited from interface jakarta.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
-
-
Constructor Summary
Constructors Constructor Description RequiredCheckboxValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
validate(FacesContext context, UIComponent component, Boolean value)
-
-
-
Method Detail
-
validate
public void validate(FacesContext context, UIComponent component, Boolean value)
-
-