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
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.
An IDE is no substitute for an Intelligent Developer.
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.