File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Form Level Error Messages In JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Form Level Error Messages In JSF" Watch "Form Level Error Messages In JSF" New topic

Form Level Error Messages In JSF

Ramesh Kumar
Ranch Hand

Joined: Dec 28, 2004
Posts: 33

I am looking for form based error message in JSF. I have different 3 different <h:form> tags in a single jsp for 3 different sections. (I am using 3 forms becuase all three forms are independent. And having individual save functionality which checks for JSF validations if click on Save. If I use single form when i click on Save of fisrt form fires Rrquired Validations of Second Form, which is not desirable).

My form structure is like following.



I Have some form level messages to show (HTML form level not page level). I am using following code to show message

FacesContext context = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage();
context.addMessage(null, msg);

Error message is showing in all the forms. In any way can I show form level mesages?.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

There is only one Messages collection for any given JSF page view. The best you can do is to provide supply a component ID to your messages as you construct them and set up the messages tags in the forms to only display messages that have that ID.

An IDE is no substitute for an Intelligent Developer.
Ramesh Kumar
Ranch Hand

Joined: Dec 28, 2004
Posts: 33
Thanks for the reply.

I solved my issue using h:message at each form and setting for attribute of that to Form Name.

In the controller I am using the componentId of the form to assign messages to respective form message.

- Ramesh
I agree. Here's the link:
subject: Form Level Error Messages In JSF
It's not a secret anymore!