JSF Mojarra extension tags – validation, focus

Here is something you may or may not know. JSF Mojarra comes with a small extension tag library with three tags: regular expression validator, credit card validator, and focus setting tag. They are available since JSF version 1.2_09, but maybe even earlier (I didn’t check).

Page setup
Before using any of the tags, add this xml namespace to your Facelet page:


Regular expression validator
mj:regexpValidator is probably all you need to validate any kind of input by setting the right expression. For example, to validate an email address:


Adding RichFaces into the mix to invoke validation onblur event.

Credit card validator
mj:creditcardValidator uses Luhn Algorithm to validate the input.


Lastly, mj:focus tags lets you set a focus on any component inside the current form:


The only thing to remember is to set for attribute to client id, not the component id.

That’s it, enjoy these “secret” tags.


  1. Axel says:

    Hi Maxa,

    I would like to use the regexValidator, but i need to customize the error message. How do I get the error message ids?


  2. max says:

    @Alex: I would look in the source code from where the messages are being retrieved. It’s possible they are in the same place as all other error messages. You can also overwrite using validatorMesssage component attribute.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.