How to write a custom converter for <p:pickList>

Viewed 61857

How can I write a custom converter when working with PrimeFaces components that use a list of POJO? My particular problem is with <p:pickList>

<p:pickList converter="????" value="#{bean.projects}" var="project" 
                             itemLabel="#{project.name}" itemValue="#{project}">

Without a converter I get java.lang.ClassCastException because JSF sets the submitted values with unconverted java.lang.String submitted values.

6 Answers

is there any way to implement that without 2 database hits?

I mean, when you have

#{bean.projects}

this is a database hit.

and when the converter puts

sBean.getProjectById(value);

is a unnecessary database hit, since bean.projects already have id and value of the objects

Related