Digital Edition

SYS-CON.TV
JSF Mojarra Extension Tags Validation and Focus
JSF Mojarra comes with a small extension tag library with three tags

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:

<h:panelGrid columns="3">
   <h:outputText value="Email:" />
   <h:inputText id="email" value="#{bean.email}"
          validatorMessage="Invalid email">
       <a4j:support event="onblur" />
       <mj:regexValidator pattern=".+@.+\.[a-z]+" />
   </h:inputText>
   <rich:message for="email" />
</h:panelGrid>

Adding RichFaces into the mix to invoke validation onblur event.

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

<h:panelGrid columns="2">
<h:outputText value="Credit card:" />
   <h:inputText id="cc" value="#{bean.creditCard}">
	<a4j:support event="onblur" />
	<mj:creditcardValidator />
   </h:inputText>
<rich:message for="cc" />
</h:panelGrid>

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

<h:form id="form">
   ...
   <h:inputText id="address" value="#{bean.address}"/>
   ...
<mj:focus for="form:address"/>
</h: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.

Read the original blog entry...

About Max Katz
Max Katz heads Developer Relations for Appery.io, a cloud-based mobile app platform. He loves trying out new and cool REST APIs in mobile apps. Max is the author of two books “Practical RichFaces” (Apress 2008, 2011), DZone MVB (Most Valuable Blogger), and is a frequent speaker at developer conferences. You can find out what Max is up to on his blog: http://maxkatz.org and Twitter: @maxkatz.



ADS BY GOOGLE
Subscribe to the World's Most Powerful Newsletters

ADS BY GOOGLE

The question before companies today is not whether to become intelligent, it’s a question of how and...
While some developers care passionately about how data centers and clouds are architected, for most,...
ChatOps is an emerging topic that has led to the wide availability of integrations between group cha...
As DevOps methodologies expand their reach across the enterprise, organizations face the daunting ch...
As Marc Andreessen says software is eating the world. Everything is rapidly moving toward being soft...
You know you need the cloud, but you’re hesitant to simply dump everything at Amazon since you know ...
Is advanced scheduling in Kubernetes achievable?Yes, however, how do you properly accommodate every ...
The cloud era has reached the stage where it is no longer a question of whether a company should mig...
The need for greater agility and scalability necessitated the digital transformation in the form of ...
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an over...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and ...
"Since we launched LinuxONE we learned a lot from our customers. More than anything what they respon...
DevOps is under attack because developers don’t want to mess with infrastructure. They will happily ...
"As we've gone out into the public cloud we've seen that over time we may have lost a few things - w...
In his session at 21st Cloud Expo, Michael Burley, a Senior Business Development Executive in IT Ser...
Sanjeev Sharma Joins June 5-7, 2018 @DevOpsSummit at @Cloud Expo New York Faculty. Sanjeev Sharma is...
We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy hig...
"I focus on what we are calling CAST Highlight, which is our SaaS application portfolio analysis too...
"Cloud4U builds software services that help people build DevOps platforms for cloud-based software a...