0

In JSF 1.2 I would like to have the HTML of <h:messages> like the following one

<ul id="messages" class="warnmessage">
 <li>Unable to link ...</li>
 <li>Unable to link ..</li>
</ul>

OR

<ul id="messages" class="errorMessage">
 <li>Unable to link ...</li>
 <li>Unable to link ..</li>
</ul>

depending on what severity of the message is. What is blocking me is that <h:messages> cannot render this html with different class assignment on <ul> level, it can be only assigned on <li> level. I would like to know if it's possibile to use this mechanism and do something like :

<h:messages styleClass="errormessage" id="errormessages" rendered="#{not empty Bean.errorMessages}"/>
<h:messages styleClass="warnmessage" id="warnmessages" rendered="#{not empty Bean.warnMessages}"/>
Mr Lister
  • 42,557
  • 14
  • 95
  • 136
Artur Skrzydło
  • 995
  • 11
  • 32
  • _" and in css3 it is no possibile to style parent depending on child classes."_ you can with some small javascript. I don't have any at hand, but reading the class from children and then run-time applying it to the parent to can work http://stackoverflow.com/questions/45004/complex-css-selector-for-parent-of-active-child – Kukeltje Apr 15 '16 at 08:16
  • @BalusC I can't use it in this way, because styleClass="messages", should define color - but it should be different depends on message type. So if i have warning messages then it should be yellow, and when error messages it should be red. – Artur Skrzydło Apr 15 '16 at 08:22
  • @Kukeltje I know how to do this in jquery, but in this case i can't use any javascript. And I'm wondering if any other solution to filter message by it's severity in jsf exists (i was trying to do this in Java by flitering getMessages() from FacesContext but without success) – Artur Skrzydło Apr 15 '16 at 08:25
  • let's say that i use . In css message class i define background-color:red. Then if warning message appears ul would have background-color:red and messages as
  • would have yellow background (because as I mentioned earlier warnClass is applied directly to li tag) . It would look really strange. Style class for ul should be consistent with
  • tags style. But it's not possbile to set it in jsf. I will edit my post with example css code and screen in a while
  • – Artur Skrzydło Apr 15 '16 at 08:40
  • i've updated my answer, with more focus on html markup i think. – Artur Skrzydło Apr 15 '16 at 09:24
  • 1
    Answer? Question you mean. This is indeed much better and certainly answerable. – BalusC Apr 15 '16 at 09:33