Let us see how we can use the Bean Validation API to specify validation constraints and perform validations using PrimeFaces client-side validations, by performing the following steps:
Create the
UserBean
class and specify the validation constraints using the Bean Validation API annotations:public class UserBean { private Integer id; @Pattern(regexp="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$", message="Invalid Email Id") private String emailId; @Size(min=2,max=5) private String password; @Size(min=1, message="FirstName should not be empty") private String firstName; private String lastName; @Pattern(regexp="^\\d{3}-\\d{3}-\\d{4}$") private String phone; @Past private Date dob; @AssertTrue(message="You must agree to Terms and Conditions") private boolean agreeToTnc; //setters and getters }
Create the User Registration...