|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
From the Blogosphere How to Highlight a Field in JSF When Validation Fails
Highlighting an input field that failed validation (or conversation) is a common UI practice today
By: Max Katz
May. 4, 2011 08:03 AM
Highlighting an input field that failed validation (or conversation) is a common UI practice today. This sort of functionality is not available in JSF (nor RichFaces) out of the box (Seam does have it). I got an email from RichFaces 4 workshop attendee from CONFESS_2011 conference asking how to do it and I thought it’s a good idea to make it blog post. It turns out, implementing such functionality is pretty simple. All we need to do is check if a particular field (component) is valid and then render or not render a style for the input field. Let’s start with the Java bean: @ManagedBean Inside isInputValid, we are searching for a particular component and checking whether it’s valid or not. JSF page: <h:head> Everything important happens here: styleClass="#{bean.inputValid?'':'inputInvalid'}"
If the component is invalid (validation has failed), then we will render inputInvalid CSS class. Otherwise, nothing is rendered. This is the result when running the page (before invoking validation): After validation:
As you can see the solution is pretty simple. Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||