| By Max Katz | Article Rating: |
|
| July 13, 2009 06:30 PM EDT | Reads: |
2,195 |
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 2,195
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.
- An Exclusive Interview with Oracle, Cloud Expo 2010 Diamond Sponsor
- Whatever the Apple iPad Is, It Apparently Leaks Like a Sieve
- Whatever Happened to JAAS?
- What’s Next for Oracle-Sun?
- Cloud Expo New York Call for Papers to Expire January 15, 2010
- Six Enterprise Megatrends to Watch in 2010
- Oracle Maps Its Cloud Computing Strategy During Cloud Expo Keynote
- Oracle’s Next Sun Hurdle
- Oracle Claims Victory Over EC; Says Sun Will Sell Clouds
- Now Russia Threatens to Hold Up Oracle-Sun Deal
- Free Virtual Appliance for Cloud Computing
- Why Cops and Java Developers Have Low Salaries?
- Kindle 2 vs Nook
- Cloud Expo New York Call for Papers Now Open
- Is Cloud Computing Like Teenage Sex?
- An Exclusive Interview with Oracle, Cloud Expo 2010 Diamond Sponsor
- Performance Tuning Essentials for Java
- Whatever the Apple iPad Is, It Apparently Leaks Like a Sieve
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Whatever Happened to JAAS?
- Cloud Computing Can Revitalize Your Career as Software Developer
- What’s Next for Oracle-Sun?
- Cloud Expo New York Call for Papers to Expire January 15, 2010
- The End of IT 1.0 As We Know It Has Begun
- 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?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?























