views:

42

answers:

1

Hi,

I use the tag h:messages for displaying form validation messages (in a red error style). I was wondering if you can use that tag to display other messages as well. For example a success message (obviously in another style) or an info message. So that I can integrate such a messages tag in any page and use it to provide information to the user.

Thank you for suggestions


Thank you for your answers.

But how does h:messages tag knows what styleClass is used for what severity ?

EDIT: Got it: infoStyle="color: green;" errorStyle="color: red;"

+2  A: 

You can do that very easily. Just use the infoStyle attribute and you can add a message like this:

class MyBean {
    ...
    public void method() {
    //do something
    String summary = "Method executed succesfully!";
    getFacesContext().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));
    }
}
Zoltan Balazs
Can you please explain a little bit or give an example :-) what's 'summary' and does the parameter, where null is? And where to add infoStyle? is there also a successStyle or errorStyle?
Sven
eg: you have a h:message on a form. You use the errorStyle attribute to show validation errors and the infoStyle attribute to show messages which severity is just INFO.
Zoltan Balazs
See http://download.oracle.com/docs/cd/E17824_01/dsc_docs/docs/jscreator/apis/jsf/javax/faces/application/FacesMessage.html . As you can see the constructor of the FacesMessage can have 3 parameters: severity, a summary string, and a detail string.
Zoltan Balazs
if you are still stuck you can see a comlete example with file uploading here: http://balusc.blogspot.com/2008/02/uploading-files-with-jsf.html
Zoltan Balazs