Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf h:messages/ h:message for specific clientId

I would like to display different FacesMessages with programmatically set clientIds. In my view I used

<h:outputText value="warnMessages #{facesContext.getMessageList('warnMessages')}" />
<h:outputText value="validationMessages #{facesContext.getMessageList('validationMessages')}" />

for debugging. The messages are all there. But...

<h:messages for="warnMessages"  />
<h:message for="warnMessages"  />

doesn't display anything. Only

<h:messages />

works. But I would like to have different message-boxes displayed together. How can I do that? Thanks

Marcel

like image 496
Marcel Menz Avatar asked Jan 24 '26 08:01

Marcel Menz


2 Answers

It look like that you're abusing client IDs to separate custom/global messages from normal validation messages.

You shouldn't do that. If you want to display a custom/global message, just don't specify any client ID. I.e., set it to null.

context.addMessage(null, facesMessage);

This way they will all appear in

<h:messages globalOnly="true" />

And use the renmant of the messages the usual way.

<h:inputText id="foo" required="true" />
<h:message for="foo" />

or

<h:messages globalOnly="false" />
like image 67
BalusC Avatar answered Jan 26 '26 00:01

BalusC


The h:messages display all messages, also those with missing client id. So the for attribute is not allowed.

The for attribute in h:message must match the id attribute of another component: in your example you have to set id="warnMessages" in whatever h:inputText you want.

like image 33
Pier Luigi Avatar answered Jan 26 '26 00:01

Pier Luigi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!