users@glassfish.java.net

RE: UISelectMany and POJOs: "Value Is Not Valid"

From: Romanowski, Tim <tim.romanowski_at_lmco.com>
Date: Fri, 30 Mar 2007 14:38:20 -0400

I understand that that is typically a solution...but it does not get rid of
the "Validation Error: Value is not valid" problem I'm having. My equals
method (below) is similar to the one you provided. However, what appears to
be happening is that on submit of a UISelectMany or UISelectOne component
(such as selectManyListbox), is that every submitted object is compared to
the original list of selectable objects; obviously, the equals method will
only return true one for each of the submitted objects, and false for as
many other selectable objects as are in the original selectable list.

As long as the submitted values are part of the original list, why am I
getting this "Validation Error: Value is not valid" message? Is there
something else I should be doing, or questioning?


Here is my Users.equals():

    public boolean equals(Object object) {
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users)object;
        if (this.username != other.username && (this.username == null ||
!this.username.equals(other.username))) return false;
        return true;
    }


And here is how I create my list of select items:
    public javax.faces.model.SelectItem[] getSupervisors() {
        EntityManager em = getEntityManager();
        List <Users> l = (List <Users>) em.createQuery("select u from Users
u").getResultList();
        em.close();
        SelectItem select[] = new SelectItem[l.size()];
        int i = 0;
        for(Users x : l) {
            select[i++] = new SelectItem(x, x.getFullName());
        }
        return select;
    }

Tim

-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: Thursday, March 29, 2007 9:38 PM
To: users_at_glassfish.dev.java.net
Subject: Re: UISelectMany and POJOs: "Value Is Not Valid"

Yap,

That is known, I usually override the 'equals' method,

For instance, with entities, I usually do the comparation with the ID of the
entity such as:

class MyEntity {
...
private long id;

@Id
public long getId() {
  return id;
}
...

@Override
    public boolean equals(Object obj) {
        if (obj instanceof MyEntity) {
            MyEntity entity = (MyEntity) obj;
            return this.id== entity.getId();
        } else {
            return false;
        }
    }


}



Asaf.
[Message sent by forum member 'trouby' (trouby)]

http://forums.java.net/jive/thread.jspa?messageID=210538

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net