user1433804
user1433804

Reputation: 657

how to change item Label in p:selectOneMenu

I have a p:selectOneMenu with the itemValue as true/false (boolean) but i want to display Yes/No instead of true/false.

<p:selectOneListbox value="#{tstMB.value}" converter="#{tstConverter}">
    <f:selectItem itemLabel="" itemValue=""/>
    <f:selectItems value="#{tstMB.valueLst}"  var="tst" 
                              itemLabel="#{tst.status}" itemValue="#{tst}"/>
</p:selectOneListbox>

in the above code tst.status returns true/false, but i want to display somethings like Yes/No.

Upvotes: 0

Views: 1130

Answers (2)

Bogdan
Bogdan

Reputation: 944

Write another method in the class which is the type of tst, let's say getDisplayStatus in which you return Yes/No instead of true/false.
Then you replace itemLabel="#{tst.status}" with itemLabel="#{tst.displayStatus}"

Upvotes: 0

partlov
partlov

Reputation: 14277

Maybe change from:

itemLabel="#{tst.status}"

to:

itemLabel="#{tst.status ? 'Yes' : 'No'}"

will help.

Of corse, if your application is localized use some localized strings in place of these string constants.

Upvotes: 1

Related Questions