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?
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.