| By Max Katz | Article Rating: |
|
| July 13, 2009 06:30 PM EDT | Reads: |
1,622 |
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 1,622
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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.
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Journal Opens "Readers' Choice Awards" Nominations
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Industry Experts Discuss the State of Cloud Computing
- It's the Java vs. C++ Shootout Revisited!
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- The End of IT 1.0 As We Know It Has Begun
- An Introduction to Abbot
- Java Kicks Ruby on Rails in the Butt
- Interviewing Java Developers With Tears in My Eyes
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- 1st Annual Government IT Expo: Call for Papers Deadline July 15
- How to Diagnose Java Resource Starvation
- REA Is Where RIA Becomes the Norm
- Kindle 2 vs Nook
- Anatomy of a Java Finalizer
- Why IBM’s Server Chief Got Busted
- 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
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?































