0

I have a jsf form to add Tasks, which are asigned to a specific worker selected from a selectOneMenu, but when i submit it throws this error

    summary=(Conversion Error setting value 'com.jpa.entities.PERSONAL@5f9f87f' for 'null Converter'.), detail=(Conversion Error setting value 'com.jpa.entities.PERSONAL@5f9f87f' for 'null Converter'.)]

Do i need to build a converter or am i making a wrong use of the select? I am new to JSF and JPA and this is driving me crazy.

XHTML:

        <b:form>
            <div class="row">
                <div class="col-md-4">
                    <h:outputLabel value="Nombre" />
                    <h:inputText styleClass="form-control"
                        value="#{tareasController.tar.NOMBRE}">
                    </h:inputText>
                </div>
                <div class="col-md-4">
                    <h:outputLabel value="Fecha de asignacion" />
                    <b:datepicker value="#{tareasController.tar.FECHA}"></b:datepicker>
                </div>
                <div class="col-md-4">
                    <h:outputLabel value="Hora limite" />
                    <b:dateTimePicker value="#{tareasController.tar.HORA_LIMITE}"></b:dateTimePicker>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <h:outputLabel value="Personal" />
                    <h:selectOneMenu value="#{tareasController.tar.PERSONAL}"
                        styleClass="form-control">
                        <f:selectItem itemLabel="Select" itemValue="#{null}" />
                        <f:selectItems value="#{tareasController.personal}" var="per"
                            itemLabel="#{per.NOMBRE}" itemValue="#{per}"></f:selectItems>
                    </h:selectOneMenu>
                </div>

            </div>
            <div class="row">
                <div class="col-md-6"
                    style="padding-top: 20px; padding-bottom: 20px;">
                    <h:outputLabel></h:outputLabel>
                    <h:commandButton class="btn btn-info" value="Guardar"
                        action="#{tareasController.addTarea(tar)}"></h:commandButton>

SERVICE:

    public void addTarea(TAREA tar) {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("WebApp");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    em.persist(tar);
    em.getTransaction().commit();
    em.close();
}

Thanks for the help.

  • 1
    Possible duplicate of [Conversion Error setting value '52' for 'null Converter'](https://stackoverflow.com/questions/13182660/conversion-error-setting-value-52-for-null-converter) – K.Nicholas Nov 20 '18 at 03:47
  • @K.Nicholas: Effectively there is a better duplicate since the link above is marked as a duplicate of https://stackoverflow.com/questions/4734580/conversion-error-setting-value-for-null-converter-why-do-i-need-a-converter – Kukeltje Nov 20 '18 at 09:47

1 Answers1

0

If you wuold like set the whole entity, than you have to create a Converter like this:

<p:selectManyMenu value="#{bean.selectedDict}" converter="omnifaces.SelectItemsConverter">
  <f:selectItems value="#{bean.dicts}" var="item" itemLabel="#{item.code} #{item.name}" itemValue="#{item}"/>
</p:selectManyMenu>

More Details: http://showcase.omnifaces.org/converters/SelectItemsConverter

László Tóth
  • 483
  • 5
  • 15
  • As mentioned with more context in the duplicate: https://stackoverflow.com/questions/4734580/conversion-error-setting-value-for-null-converter-why-do-i-need-a-converter – Kukeltje Nov 20 '18 at 10:42