0

I have a form with a panelGrid, where the user puts in some data:

<h:form>
    <p:panelGrid var="workOrder" value="#{WorkOrder}" columns="2"
        headerClass="header" footerClass="footer">
        <p:outputLabel value="#{msg.project_number}: " for="projectNr" />
        <p:column>
            <p:inputText id="projectNr"
                value="#{mbWorkOrderController.workOrderCurrent.projectNr}"
                required="true" requiredMessage="#{msg.input_missing}"
                maxlength="6" />
        </p:column>
        <p:outputLabel value="#{msg.date}: " for="date" />
        <p:column>
            <p:calendar id="date"
                value="#{mbWorkOrderController.workOrderCurrent.date}"
                mode="popup" navigator="true" showOn="button"
                pattern="dd.MM.yyy" />
        </p:column>
    </p:panelGrid>
    <p:commandButton action="#{mbWorkOrderController.saveWorkOrder()}"
        value="#{msg.save}" style="margin-top: 10px" />
    <p:commandButton
        action="#{mbWorkOrderController.cancelWorkOrder()}"
        value="#{msg.cancel}" immediate="true" style="margin-top: 10px" />
</h:form>

When the user clicks "save", the method saveWorkOrder() is called. Inside, I am trying to use the method setWrappedData() on a DataModel variable, after I create the result using the EntityManagerss createNamedQuery():

public String saveWorkOrder() {
    try {
        utx.begin();
        workOrderCurrent = em.merge(workOrderCurrent);
        em.persist(workOrderCurrent);
        List<WorkOrder> resultList = em.createNamedQuery("SelectWorkOrders").getResultList();
        workOrdersList.setWrappedData(resultList);
        utx.commit();
    } catch (NotSupportedException e) {
        e.printStackTrace();
    } catch (SystemException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (RollbackException e) {
        e.printStackTrace();
    } catch (HeuristicMixedException e) {
        e.printStackTrace();
    } catch (HeuristicRollbackException e) {
        e.printStackTrace();
    }
    return "rainErosion";
}

Unfortunately I am getting a NullPointerException in setWrappedData(resultList) although resultList contains one element (with the actual user input) and is not pointing to Null, so normaly this shouldn't happen.

Does anyone know, why this happens?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
John
  • 795
  • 3
  • 15
  • 38
  • 2
    Your question is ambiguous. Are you capable of reading stack traces and debugging variables? Have you already excluded `workOrdersList` itself from being `null`? If not, then I agree Jens' closure. – BalusC Apr 13 '16 at 08:05
  • True, I added a `@PostConstruct` method where I create a new `workOrdersList` object. It works now. Sorry. – John Apr 14 '16 at 07:03

0 Answers0