Why selectOneMenu Send ItemLabel to the converter?

前端 未结 4 2162
孤独总比滥情好
孤独总比滥情好 2020-12-01 17:20

my JSF page



                      
     

        
4条回答
  •  再見小時候
    2020-12-01 17:51

    BalusC (again) nailed this one for me. I had the same problem and as BalusC pointed out earlier my converter's getAsString() method returned my object's "firstname" property.

    @Override public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value == null || value.equals("")) {
            return "";
        }
        else {
            return String.valueOf(((Employee) value).getfirstname());
        }
    
    }
    

    I changed this to return the id and it started working as expected.

    @Override public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value == null || value.equals("")) {
            return "";
        }
        else {
            return String.valueOf(((Employee) value).getId());
        }
    
    }
    

    BalusC your effort to explain the theory is hugely appreciated. You're heavensent!

提交回复
热议问题