Surface selectOneMenu does not work when necessary.

I am losing days with this strange problem, I checked everything twice, but my selectOneMenu just doesn’t work, and I can’t understand why.

So here are my codes:

My jsf

<p:selectOneMenu id="entityType"  
      value="#{entityBean.entity.type}" 
      style="width:240px;" 
      converter="entityTypeConverter"
      valueChangeListener="#{entityBean.entityTypeListener}"
      required="true">
      <f:selectItems value="#{entityBean.typeList}"
              var="et"
              itemLabel="#{et.name}"
              itemValue="#{et}" />
</p:selectOneMenu>

My converter:

    @FacesConverter("entityTypeConverter")
    public class EntityTypeConverter implements Converter {
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
            if (value == null || value.length() == 0) {
                return null;
            }
            Long id = Long.parseLong(value);

            return EntityType.findEntityType(id);
        }

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

            return value instanceof EntityType ? ((EntityType) value).getId().toString() : "";
        }
    }

It works as expected when I create (it passes the selected value), but when I try to edit the object, the selected type will actually never be selected. I tried with performances 3.1.1 and 3.2, but I can not get the selected value in the view / edit mode.

What am I doing wrong?

Thanks in advance!

+3
source share
1 answer

, equals() EntityType . , id EntityType, , -, , :

@Override
public boolean equals(Object other) {
    return (other instanceof EntityType) && (id != null)
        ? id.equals(((EntityType) other).id)
        : (other == this);
}

@Override
public int hashCode() {
    return (id != null)
        ? (this.getClass().hashCode() + id.hashCode())
        : super.hashCode();
}

hashCode() equals() .

+10

All Articles