我有一个带有panelGrid的表单,用户可以在其中输入一些数据:
<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>
当用户点击“保存”时,会调用方法saveWorkOrder()
。在我使用setWrappedData()
s DataModel
创建结果后,我试图在EntityManagers
变量上使用方法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";
}
不幸的是我在NullPointerException
中获得了setWrappedData(resultList)
,虽然resultList
包含一个元素(包含实际的用户输入)并且没有指向Null
,所以通常情况下这不应该不会发生。
有谁知道,为什么会这样?