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:

xmlns:mj="http://mojarra.dev.java.net/mojarra_ext"

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.



   
	
	
   


Focus
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.

3 thoughts on “JSF Mojarra extension tags – validation, focus

  1. 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?

    Axel

  2. @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 Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s