简体   繁体   English

JSF <h:message /> 内 <h:graphicImage /> 标题

[英]JSF <h:message /> inside <h:graphicImage /> title

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. 试图将UIComponent <h:message />对象绑定到控制器对象,但是后来我不知道如何从UIComponent获取跨度的值。

What should I do? 我该怎么办?

Just control the markup yourselves inside an <ui:repeat> while iterating over the messages. 遍历消息时,只需在<ui:repeat>控制自己的标记即可。 You can obtain messages in EL by FacesContext#getMessageList() . 您可以通过FacesContext#getMessageList()在EL中获取消息。

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. #{message}FacesMessage的实例,提供了通常的吸气剂。

An alternative solution is to define and put all these long messages in .properties 's file, as bundle messages. 另一种解决方案是将所有这些长消息定义为束消息并将其放在.properties的文件中。 Take a look here : When to use message bundle and resource bundle 在这里看看: 何时使用消息包和资源包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM