File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Validation " Watch "Validation " New topic
Author

Validation

deepa durai
Greenhorn

Joined: May 08, 2007
Posts: 18
I need to validate a textfield.If it fails, i don't want to diaplay exception thrown by the JSf..
I just want to display the fields in red color and to display a global message"Fields in Red are error fields" .How can i achieve this?

I tried the following the code .It displays the message adjacent to the field.But i need my message to be displayed on top.Please help me

IBD Name:<h:message for="ibdName"/>
<h:inputText id="ibdName" name="ibdName" size="5" class="TextBlackNormal" value="#{MSPSAdminBean.ibdInfoBean.ibdName}" errorStyle="color:red"> <f:validateLength maximum="1"/> </h:inputText>


Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

You can use the <h:messages/> element to display "messages on top" or on bottom, or anywhere else you want a bullet list or table of messages to display. However, the tricky part is going to be in adding your custom message to it. Validation errors handled without invoking user application code, so there's no user code to detect the error condition or to insert your message.

I expect you'll probably have to do some sort of phase listener function in order to be able to intercept, detect, and act in the way you want to.

That's the hard part. The other day I had to do something sort of similar and I detected the presence of validation errors by obtaining access to the context messages and checking to see if any were present.

Customer surveys are for companies who didn't pay proper attention to begin with.
Vinc Coop
Greenhorn

Joined: Jul 14, 2009
Posts: 3
which server do you use?

I can say that with my glassfish as the example works and no exception is thrown. please post additionally the exception text.

I hope i could help you
deepa durai
Greenhorn

Joined: May 08, 2007
Posts: 18
hi

Thanks Tim and vinc..

using <h:messages/> i am able to display the message wherever i want.
Can you tell me how to display the label in red color when error occurs or validation fails.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

The messages tag supports different style classes for different severity levels. I believe that the name of the one for validation errors is "errorClass", but check the documentation to be sure. There's no distinction between validation errors and other types of errors.
 
wood burning stoves
 
subject: Validation
 
Similar Threads
How to check if textboxes are null
Trying to Learn Struts: Errors
html:errors - do not want &gt;ul&lt; tags in HTML
How to send email in text format?
If no matching records found, how do I display a message?