I'm using JSF 2.0. I'm using the
<h:messages>
tag to render error messages. I can use css to style my messages a little bit but I've create a composite component to render messages that can be closed and adding effects to them with some Jquery.
I've seen tutorials on how to customize the messages, but most of these rely on css and customizing the text output yet what I want to do is generate specific markup, something like
<myComp:fancyMessage text="etcetcetc error msg" type="error" />
instead of the regular message markup. Is this possible?
EDIT:
I don't want to style up jsf messages. Neither add background nor change its style, but rather create my own message html markup. Here:
http://balusc.blogspot.com/2010/07/using-html-in-jsf-messages.html
I've found how to add html to your messages. What I want is to encapsule all the html in my composite component, and then just use my composite component in this way:
<mycomp:messages/>
or
<mycomp:message for="componentID" />
where message and messages both create their own html markup
Use FacesContext#getMessageList()
inside ui:repeat
. Each item is a FacesMessage
which has several getters.
<ui:repeat value="#{facesContext.messageList}" var="facesMessage">
Severity: #{facesMessage.severity}<br />
Summary: #{facesMessage.summary}<br />
Detail: #{facesMessage.detail}<br />
<br />
</ui:repeat>
This allows for more fine-grained HTML markup around the messages.
And it also enables you to print them as HTML with help of <h:outputText escape="false">
. I might need to expand and revise my blog article sooner or later :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With