Adding client-side capabilities to the validator
Adding client-side capabilities to the validator can save a round trip to the server, which can greatly improve performance.
In this recipe, we will add client-side capabilities to the EmailValidator
. You can continue from the previous recipe, or you can grab this project's recipe by cloning the CreatingCustomCSValidator
application from the Git repository.
Getting ready
In order to add the client-side capabilities to the validator, we need to do two things:
Create a JavaScript version of the validator following the documentations.
Implement the
org.apache.myfaces.trinidad.validator.ClientValidator
interface and override its methods.
The second step is important since even though we are creating a client-side validator, we need to have server-side code in case someone was trying to mimic a POST. So, we need to extend the original EmailValidator
class to support the client-side functionality and add the necessary JavaScript at runtime.