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 explosion of new web/cloud/IoT-based applications and the data they generate are transforming ou...
CI/CD is conceptually straightforward, yet often technically intricate to implement since it require...
Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple ...
Enterprises are striving to become digital businesses for differentiated innovation and customer-cen...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As au...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't com...
The now mainstream platform changes stemming from the first Internet boom brought many changes but d...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, wi...
DXWorldEXPO LLC announced today that Ed Featherston has been named the "Tech Chair" of "FinTechEXPO ...
Chris Matthieu is the President & CEO of Computes, inc. He brings 30 years of experience in developm...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: D...
Andi Mann, Chief Technology Advocate at Splunk, is an accomplished digital business executive with e...
In this presentation, you will learn first hand what works and what doesn't while architecting and d...
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitori...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use ...
If your cloud deployment is on AWS with predictable workloads, Reserved Instances (RIs) can provide ...
Disruption, Innovation, Artificial Intelligence and Machine Learning, Leadership and Management hear...
We build IoT infrastructure products - when you have to integrate different devices, different syste...
Consumer-driven contracts are an essential part of a mature microservice testing portfolio enabling ...