webtier@glassfish.java.net

Re: getting object in h:selectOneMenu and f:selectItems

From: <webtier_at_javadesktop.org>
Date: Thu, 22 Jul 2010 11:44:37 PDT

You will need to implement and register a Converter for the MyClass class. The Converter handles the conversion from server side java object to client side string representation.

Eg.

[code]
@javax.faces.convert.FacesConverter(forClass=MyClass.class)
public MyClassConverter implements javax.faces.convert.Converter {
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return new MyClass(value);
    }
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return ((MyClass) value).getUniqueName();
    }
}
[/code]

Further ensure that the object has proper implementations of hashCode and equals.
[Message sent by forum member 'janderssn']

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