Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation

 
deepa durai
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18214
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vinc Coop
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18214
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic