uCosminexus Application Server, Web Container Functionality Guide
This section describes the procedure for using the Bean Validation from JSF.
You must satisfy the following conditions for using the Bean Validation verification functionality in JSF:
The validation process of the Bean Validation differs according to the values set in the context parameter of JSF. The behavior of the Bean Validation differs according to the values set in javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR and depending upon whether the f:validateBean tag is specified for the ManagedBean that defines the annotation of the Bean Validation.
Table 3-13 Relation of the values set in javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR and the validation process
Value set in javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR | If the <f:validateBean> tag is specified (when the disabled attribute is not specified) | If validation is done by the Bean Validation |
---|---|---|
true | Yes | Yes |
No | No | |
false | Yes | Yes |
No | Yes | |
If no value is specified (default) | Same as in the case of false | Same as in the case of false |
For details on how to use the f:validateBean tag, see Standard specifications of JSF.
For details on how to define a validation for ManagedBean variables, see Standard specifications of Bean Validation.
The following is an example of implementation done for using the Bean Validation from JSF.
The following is an example of implementing a Facelets page that registers the information which requires validation.
<f:view> <h:form> Enter ID<br/> <h:inputText id="IDBox" value="#{personalData.id}" /><br/> <h:message for="IDBox"/><br/> <br/> <f:validateBean disabled="true"> Enter name (validation will not be performed) <br/> <h:inputText id="NameBox" value="#{personalData.name}" /><br/> </f:validateBean > <br/> Enter age <br/> <h:inputText id="AgeBox" value="#{personalData.age}" /><br/> <h:message for="AgeBox"/><br/> <br/> <br/> : : </h:form> </f:view> |
Next is an implementation example of the validation definition for the ManagedBean that stores the data, which requires validation.
@ManagedBean(name="personalData") @SessionScoped public class PersonalData { @Size(min=8,max=12, message="Enter a string between 8 to 12 characters inclusive.") private String id = ""; @Size(min=1,message="Enter name.") private String name = ""; @Max(value = 150, message="Confirm if the correct age is entered.") @Min(value = 0, message="Age must be 0 or above.") private int age = 0; : setter/gettter method : } |
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.