1
votes

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;"

1

1 Answers

4
votes

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));
    }
}