jsfconvertersselectonemenu

selectOneMenu Conversion Error setting value for 'null Converter'


I have two entities which are in a relationship:

// Produkt
@ManyToOne
private Hersteller hersteller;

// Hersteller
@OneToMany(targetEntity = Produkt.class)
private List<Produkt> produkte;

I have a jsf form to edit a Produkt entity (which works fine yet). Now i want to change the "Hersteller" of a "Produkt".

<h:selectOneMenu styleClass="form-control" id="hersteller" value="#adminProduktMgmtHandler.produkt.hersteller}">
          <f:selectItems value="#{adminProduktMgmtHandler.hersteller}" var="hersteller" itemLabel="#{hersteller.name}" itemValue="#{hersteller}" />
</h:selectOneMenu>

The output is correct, but when i submit it i get the following error:

Conversion Error setting value for 'null Converter'

The generated html:

<select id="kunden-form-register:hersteller" name="kunden-form-register:hersteller" class="form-control" size="1">  <option value="de.hsb.app.gws.model.Hersteller@2169a647">Coca Cola</option>
    <option value="de.hsb.app.gws.model.Hersteller@3d9db94c">PepsiCo</option>
</select>

Im a newbie in jee/jsf, but afaik it should work by passing the object correctly right? I don't have to use a id a itemValue to set it?


Solution

  • Solution: Okay, works by just setting the id as itemValue...

    <h:selectOneMenu styleClass="form-control" id="hersteller" value="#{adminProduktMgmtHandler.produkt.hersteller.id}">
        <f:selectItems value="#{adminProduktMgmtHandler.hersteller}" var="hersteller" itemLabel="#{hersteller.name}" itemValue="#{hersteller.id}" />
    </h:selectOneMenu>