Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF. Convert value for h:commandLink display

Tags:

jsf

jsf-2

I am passing Status object to h:commandLink value. So it is displayed on the page. The problem is, displayed string is

packages.entity.Status@db2674c8.

I created converter for Status with annotation

@FacesConverter(forClass = Status.class, value = "statusConverter")

but it doesn't work. I tried to explicitly set it:

<h:commandLink value="#{result.status}" action="/view">
    <f:converter converterId="statusConverter" />
</h:commandLink>

Then I got an error: /search-form.xhtml @57,58 <f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlCommandLink@53e387f3

which is quite true, h:commandLink is not ValueHolder. Is there some way to convert value for h:commandLink?

like image 697
amorfis Avatar asked Dec 16 '22 13:12

amorfis


1 Answers

Interesting, I'd intuitively expect it to work here, but the UICommand does indeed not extend UIOutput (while the UIInput does). It's maybe worth an enhancement request to JSF boys.

You can go around this issue by displaying it using <h:outputText>.

<h:commandLink action="/view">
    <h:outputText value="#{result.status}">
        <f:converter converterId="statusConverter" />
    </h:outputText>
</h:commandLink>

Or just without explicit <f:converter> since you already have a forClass=Status.class

<h:commandLink action="/view">
    <h:outputText value="#{result.status}" />
</h:commandLink>
like image 69
BalusC Avatar answered Dec 27 '22 16:12

BalusC