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 EntityManagers
s 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?