0

So, I am trying to display validation error messages as image title. I want to do that, because messages are quite long and I don't want them to take place on my page.

Tried to bind UIComponent <h:message /> object to controller object, but then I couldn't find out how to get a span's value from UIComponent.

What should I do?

2 Answers2

1

Just control the markup yourselves inside an <ui:repeat> while iterating over the messages. You can obtain messages in EL by FacesContext#getMessageList().

So instead of,

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

do something like

<h:inputText binding="#{foo}" ... />
<ui:repeat value="#{facesContext.getMessageList(foo.clientId)}" var="message">
    <h:graphicImage name="#{message.severity}.png" title="#{message.summary}" />
</ui:repeat>

where the #{message} is an instance of FacesMessage, offering the usual getters.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

An alternative solution is to define and put all these long messages in .properties's file, as bundle messages. Take a look here : When to use message bundle and resource bundle

Community
  • 1
  • 1
Omar
  • 1,430
  • 1
  • 14
  • 31
  • Thx for the reply, and yes, I know that I can override these messages. Still, do you think that the only possible solution is to make these messages shorter and there is no way to put them as image's title? – Karolis Tarasaitis Feb 03 '14 at 06:21
  • Maybe it's possible, but it gonna be more complicated (more code in the backing-beans). – Omar Feb 03 '14 at 08:54
  • Not a problem actuallly. The only thing I need, is to find out how to get `Validation message` validation message from UIComponent. Probably I will leave it for now, unless someone will give me a hint. – Karolis Tarasaitis Feb 03 '14 at 09:11