users@glassfish.java.net

UISelectMany and POJOs: "Value Is Not Valid"

From: Romanowski, Tim <tim.romanowski_at_lmco.com>
Date: Thu, 29 Mar 2007 18:10:25 -0400

Hi guys,
I'm trying to use a selectManyListbox (actually, any UISelectMany component)
that is populated with a list of POJOs. The problem is, as I've found to be
common from searching the web, that validation always fails when the POJOs
are converted by either 1) creating a new object or 2) getting an instance
of the POJO from a persistent layer (such as a database). During the
validation phase, the submitted values are converted and then compared to
the original list; the submitted values, however, will not match the
original list because they are re-retrieved from the database. How does
everyone work around this?

 

The issue I'm running into is described at [1]. Basically, I create an
ArrayList of my own User objects, and pass that as the value for my
component as such:

 

<h:selectManyListbox id="teamMembers" value="#{team.userCollection}">

                       <f:selectItems value="#{team.userSelectItems}"/>

                   </h:selectManyListbox>

 

The "getUserSelectItems" method returns an array of SelectItems, each having
a value equal to a user object, and a label equal to the fullname of the
user.

 

The problem: when submitting the form containing the Picklist, I get a
validation error "j_id64:teamMembers: Validation Error: Value is not
valid"

 

What is the correct way to handle this problem, as described in [1]? This
seems like a fairly common use case, but I have not been able to figure out
how others are getting this to work, such as at [2] and [3].

Do I need to use my own UISelectMany validate method? Is there an elegant
solution?

 

 

Tim

 

[1]
http://www.crazysquirrel.com/computing/java/jsf/converter-validation-error.j
spx

[2] http://forum.java.sun.com/thread.jspa?threadID=521178&start=0&tstart=0

[3]
http://blog.etiviti.com/2004/05/jsf-selectmany-results-in-value-is-not-valid
-errors/