我路过Status
对象为 h:commandLink 值。所以页面上就显示出来了。问题是,显示的字符串是
packages.entity.Status@db2674c8
。
我为 Status
创建了转换器带注释
@FacesConverter(forClass = Status.class, value = "statusConverter")
但它不起作用。我尝试明确设置它:
<h:commandLink value="#{result.status}" action="/view">
<f:converter converterId="statusConverter" />
</h:commandLink>
然后我得到一个错误:/search-form.xhtml @57,58 <f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlCommandLink@53e387f3
这是真的,h:commandLink
不是ValueHolder
。有没有办法转换 h:commandLink
的值?
最佳答案
有趣,我直觉地希望它在这里工作,但是 UICommand
确实没有扩展 UIOutput
(而 UIInput
则如此)。也许值得向 JSF 男孩提出增强请求。
您可以通过使用 <h:outputText>
显示它来解决此问题.
<h:commandLink action="/view">
<h:outputText value="#{result.status}">
<f:converter converterId="statusConverter" />
</h:outputText>
</h:commandLink>
或者只是没有明确的 <f:converter>
因为你已经有了 forClass=Status.class
<h:commandLink action="/view">
<h:outputText value="#{result.status}" />
</h:commandLink>
关于JSF。转换 h :commandLink display 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6098279/