I’m creating error messages this way:
public static void setErrorMessage(String errorMessage) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(errorMessage));
}
and showing them on the form in case of error (red color):
<h:messages styleClass="error"/>
How to separate error and success messages in JSF? Simply, how to show the positive messages in green color and the negativ in red?
Use the
errorClassandinfoClassattributes instead to specify different style classes for those severities (there are alsowarnClassandfatalClass, see also tag documentation):The
styleClasscovers the unmatched severities. You only need to change the way how you created the message. When you don’t specify the severity, it defaults to “info”. See also theFacesMessagejavadoc.