In theory, you want an escape
attribute for the h:messages
component like the h:outputText
has. You’re not the only one who wants this, this is requested before more than often, but it’s a WONTFIX according the JSF guys.
You have several options:
-
Use
\n
instead of<br>
and apply CSS accordingly (easiest).#messages td { white-space: pre; }
-
Create a custom renderer which extends
MessageRenderer
(bit harder, but nice if you want to cover more HTML than only linebreaks). -
Gather the messages yourself in some
List
in a bean and display them using<t:dataList>
, or when you’re already using Facelets instead of JSP, using<ui:repeat>
. This way you can use<h:outputText escape="false">
to display the individual messages. -
Or, when you’re already on JSF 2.0, just iterate over
FacesContext#getMessageList()
yourself. Each item gives you aFacesMessage
back which in turn offers several getters. You could then display the summary in a<h:outputText escape"false" />
.<ul> <ui:repeat value="#{facesContext.messageList}" var="facesMessage"> <li> <h:outputText value="#{facesMessage.summary}" escape="false" /> </li> </ui:repeat> </ul>
-
Or, when you’re using JSF utility library OmniFaces, use its
<o:messages>
component instead which has support forescape
attribute.<o:messages escape="false" />