My Objective is to use h:messages to convey user – error and confirmation messages. The CSS styles to show these two different messages are different, In fact I would like to use an image beside the confirmation message.
e.g. :
<tr>
<td>
<img/>
</td>
<td>
<h:msg>
</td>
</tr>
So I tried to add messages to the Faces Context based on 2 different client ids
<tr>
<td height="5">
<h:messages style="color:darkred" id="error_message" />
</td>
</tr>
<tr>
<td width="89%" class="InfoMsg" align="center">
<h:messages id="confirm_message" />
</td>
</tr>
And the java layer:
FacesMessage facesMessage = new FacesMessage(Constants.saveMessageConfirm);
FacesContext.getCurrentInstance().addMessage(Constants.STATIC_CONFIRM_MSG_CLIENT_ID, facesMessage);
But, even if I add messages to clientId confirm_message – and only to confirm_message – and not to error_message – The message is shown twice in 2 different styles (refer the HTML above).
2 Questions :
-
What is the problem here?
-
If I want to show the image inside a
tdin the secondtrand conditionaly show that secondtrwhen confirm messages are present – what is the best way?
Thanks
The
h:messagesdisplays all messages, also the ones which are already displayed in ah:messagein the page. You can however set it to only display messages with anullclient ID usingglobalOnly="true".You can also give the message a different style depending on the
FacesMessage.Severity:with for example this CSS which hides the
INFOmessages and makesERRORmessages red:You can use
redisplay="false"to tell it to not display the already displayed messages via e.e.<h:message>.You only need to make sure it’s placed in the component tree after all those other message components. You can if necessary make use of CSS to reposition it somewhere in top.
Just to be sure,
this will attach the given message to a
<h:message for="clientId">not to a<h:messages id="clientId">as you seem to expect.