| By Max Katz | Article Rating: |
|
| July 13, 2009 06:30 PM EDT | Reads: |
301 |
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...
Published July 13, 2009 Reads 301
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Max Katz
Max Katz is a Senior Systems Engineer at Exadel. He has been helping customers jump-start their RIA development as well as providing mentoring, consulting, and training. Max is a recognized subject matter expert in the JSF developer community. He has provided JSF/RichFaces training for the past four years, presented at many conferences, and written several published articles on JSF-related topics. Max also leads Exadel's RIA strategy and writes about RIA technologies in his blog, http://mkblog.exadel.com. He is an author of "Practical RichFaces" book (Apress). Max holds a BS in computer science from the University of California, Davis.
- Java Kicks Ruby on Rails in the Butt
- Ulitzer’s Amazing First 30 Days in Public Beta
- 1st Annual Government IT Expo: Call for Papers Deadline July 15
- REA Is Where RIA Becomes the Norm
- Will Ulitzer Dominate News Content on The Web? -Gartner
- Java Persistence on the Grid: Approaches to Integration
- Oracle-Sun: Schwartz Is Toast - Miko Matsumara
- Using the IBM Thread & Monitor Dump Analyzer for Java Technology
- It's the Java vs. C++ Shootout Revisited!
- Is Cloud Computing Like Teenage Sex?
- Performance of Java Compilers: An Empirical Study
- Java Kicks Ruby on Rails in the Butt
- Developing Rich Client Applications Using Swing - II
- The Right Time for Real Time Java
- Xpress Suite Adds Automatic Java to iPhone Conversion
- Ulitzer’s Amazing First 30 Days in Public Beta
- 1st Annual Government IT Expo: Call for Papers Deadline July 15
- Initial Thoughts on IBM Acquisition of Sun Microsystems
- REA Is Where RIA Becomes the Norm
- Maximizing Java Performance with Bespoke Programming
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- What's New in Eclipse?
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate

































