我有两个带有自己的panelGroup的Primeface数据表。 一个用于从用户输入。 第二个用于显示数据库中的数据。 它取决于selectOneMenu选项。
XHTML文件:
<h:body>
<h:form id="form">
<!-- Select One Menu For Invoice Data -->
<br />
<h3 align="center">Tax Invoice</h3>
<p:selectOneMenu id="selectOne" value="#{invoiceBean.selectOneOption}"
required="true">
<f:selectItem itemValue="Add New Invoice" itemLabel="Add New Invoice" />
<f:selectItem itemValue="Old Invoice" itemLabel="Old Invoice" />
<f:ajax render="groups" />
</p:selectOneMenu>
<h:panelGroup id="groups">
<h:panelGroup id="inputs"
rendered="#{invoiceBean.selectOneOption == 'Add New Invoice'}">
<table border="1" id="invoiceData">
<tr>
<td> 1 </td>
<td> 2 </td>
</tr>
</table>
</h:panelGroup>
<h:panelGroup id="outputs"
rendered="#{invoiceBean.selectOneOption == 'Old Invoice'}">
<p:panelGrid columns="3">
<p:outputLabel value="Enter Invoice Number :" />
<p:inputText id="inputInvoiceNumber"
value="#{invoiceBean.invoiceNumber}" />
<p:commandButton value="Search" type="submit">
<f:ajax execute="inputInvoiceNumber" render="outputInvoiceNumber" />
</p:commandButton>
</p:panelGrid>
<br />
<p:dataTable id="outputInvoiceNumber"
value="#{invoiceBean.invoiceByContrId}" var="invoice">
<p:column headerText="Invoice Id ">
<p:outputLabel value="#{invoice.id}" />
</p:column>
</p:dataTable>
</h:panelGroup>
</h:panelGroup>
</h:form>
</h:body>
Managed Bean Mothod:
public List<Invoice> getInvoiceByContrId() {
invoiceDao = new InvoiceDao();
invoices = new ArrayList<Invoice>();
try {
invoices = invoiceDao.getInvoiceId(invoiceNumber);
if (null == invoices) {
invoices = Collections.emptyList();
}
return invoices;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
invoices = Collections.emptyList();
return invoices;
}
}
InvoiceDao类获取发票数据:
public List<Invoice> getInvoiceId(String invoiceNumber) {
List<Invoice> invoiceList = new ArrayList<Invoice>();
try {
startReadOperation();
System.out.println("InvoiceDao.getIpsData()");
String sql = "SELECT * FROM invoice where invoice_number = :invoiceNumber";
SQLQuery query = session.createSQLQuery(sql);
query.setParameter("invoiceNumber", invoiceNumber);
query.addEntity(Invoice.class);
invoiceList = query.list();
} catch (Exception e) {
e.printStackTrace();
return null;
}
finally {
endOperation();
}
return invoiceList;
}
现在,我希望发票表中的数据按照根据要求由用户输入的invoice_number。
错误是:
javax.el.ELException: /index.xhtml @132,60 value="#{invoiceBean.invoiceByContrId}": Error reading 'invoiceByContrId' on type com.billing.managebeans.InvoiceBean
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:1002)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:629)
at javax.faces.component.UIData.getRowCount(UIData.java:356)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:762)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:744)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:258)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:220)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:84)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
at com.billing.dao.AbstractDao.commit(AbstractDao.java:46)
at com.billing.dao.AbstractDao.endOperation(AbstractDao.java:60)
at com.billing.dao.InvoiceDao.getInvoiceId(InvoiceDao.java:108)
at com.billing.managebeans.InvoiceBean.getInvoiceByContrId(InvoiceBean.java:213)
at sun.reflect.GeneratedMethodAccessor136.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 49 more
在Tomcat服务器中运行代码时出现错误。 它包含空指针异常错误和其他。