I would like to add a header and footer image to a h:message in JSF 2.0 so it has nice borders.
It looks like the way to do this is to implement a custom renderer for a component and write out the tags. Id like to do this as a composite component but I cant figure out how to say ‘dont draw the header and footer unless youre drawing the message’.
Is there a way to do this with a composite component?
Im using mojarra.
You can use
FacesContext#messageList(String clientId)to get aList<FacesMessage>with all messages for a specific client ID (of which you’d usually be interested in only the first one, you can change the below example if you want). So you could just check in therenderedattribtue if the list is not empty. Then you can use<h:outputText escape="false">to display the message without implicitly escaping HTML. You could if necessary wrap it all in a composite to keep your code DRY.Note that this method was not available in JSF 1.x, that’s why you’d need to create a custom component for it.