JSF.转换h:commandLink显示的值

amo*_*fis 4 jsf jsf-2

我将Status对象传递给h:commandLink值.所以它显示在页面上.问题是,显示字符串是

packages.entity.Status@db2674c8.

我为Status注释创建了转换器

@FacesConverter(forClass = Status.class, value = "statusConverter")
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我试着明确地设置它:

<h:commandLink value="#{result.status}" action="/view">
    <f:converter converterId="statusConverter" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)

然后我收到一个错误: /search-form.xhtml @57,58 <f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlCommandLink@53e387f3

这是真的,h:commandLink不是ValueHolder.有没有办法转换价值h:commandLink

Bal*_*usC 11

有趣的是,我直觉地期望它在这里起作用,但UICommand确实没有扩展UIOutput(同时UIInput确实如此).这可能值得JSF男孩的增强请求.

你可以通过使用它来解决这个问题<h:outputText>.

<h:commandLink action="/view">
    <h:outputText value="#{result.status}">
        <f:converter converterId="statusConverter" />
    </h:outputText>
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)

或者只是没有明确,<f:converter>因为你已经有了forClass=Status.class

<h:commandLink action="/view">
    <h:outputText value="#{result.status}" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)