myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael Santini" <raf...@santini.eti.br>
Subject Generic Type
Date Thu, 06 Mar 2008 15:34:02 GMT
When a property is implemented with generic type, a conversion
exception is throw ed:

Value is no String (class=java.lang.Integer, value=1)

To reproduce the problem:

public interface GenericEntity<Id> {

    public Id getId();

}

public class OptionEntity implements GenericEntity<Integer>, Serializable {

    private Integer id;

    private String option;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getOption() {
        return option;
    }

    public void setOption(String option) {
        this.option = option;
    }

}

public class TestBean implements Serializable {

    private OptionEntity option = new OptionEntity();

    public OptionEntity getOption() {
        return option;
    }

    public void setOption(OptionEntity option) {
        this.option = option;
    }

    public Map<String, Integer> getOptions() {
        Map<String, Integer> result = new TreeMap<String, Integer>();
        result.put("I", 1);
        result.put("II", 2);
        result.put("III", 3);
        return result;
    }

}

<h:form>
  <h:selectOneMenu value="#{testBean.option.id}">
    <f:selectItems value="#{testBean.options}"/>
   </h:selectOneMenu>
</h:form>

Mime
View raw message