O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Triggering client-side validations based on events

The client-side validations get triggered when the form is submitted, that is when you click on the command component with the validateClient attribute set to true. But sometimes, we may want to show validation errors immediately instead of waiting for the user to submit the form.

We can enable instant validations using <p:clientValidator/> for various events such as change(default), blur, keyup, and so on, as follows:

<p:inputText id="emailId" value="#{userController.registerUser.emailId}" label="EmailId" 
    required="true" validatorMessage="#{msg['invalid.email']}">
    <f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
 <p:clientValidator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required