首先,代码:
<p:dataTable id="tablePriceCriteria" value="#{kuBean.criteriaList}" selection="#{kuBean.selectedCriteriaList}" var="criteria">
<p:column selectionMode="multiple" style="width: 50px;"/>
<p:column>
<f:facet name="header">
<h:outputText value="Criteria name" />
</f:facet>
<h:outputText value="#{criteria.criteriaPK.criteriaName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Measure unit" />
</f:facet>
<h:outputText value="#{criteria.measureUnit}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Size" />
</f:facet>
<h:outputText value="#{criteria.criteriaPK.size}" />
</p:column>
<f:facet name="footer">
<p:commandButton value="Add criteria to service" actionListener="#{kuBean.addPricesToService}"
oncomplete="wiz.next()"/>
</f:facet>
</p:dataTable>
</p:panel>
</p:tab>
<p:tab id="Prices" title="Price">
<p:panel>
<p:dataTable value="#{kuBean.service.pricesList}" var="price">
<f:facet name="header">
Usluga: #{kuBean.service.serviceName}
</f:facet>
<p:column headerText="Criteria name">
<f:facet name="output">
<h:outputText value="#{price.criteria.criteriaPK.criteriaName}"/>
</f:facet>
</p:column>
<p:column headerText="Measure unit">
<f:facet name="output">
<h:outputText value="#{price.criteria.measureUnit}"/>
</f:facet>
</p:column>
<p:column headerText="Size">
<f:facet name="output">
<h:outputText value="#{price.criteria.criteriaPK.size}"/>
</f:facet>
</p:column>
<p:column headerText="Service Price">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{price.price}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{price.price}" style="width: 100%;"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
当我查看代码时,我意识到任何人都无法理解任何东西,所以我试着解释一下这里发生了什么。
我在数据库中有表(主键是粗体):
服务: serviceID ,serviceName
标准: criteriaName,size ,measureUnit
价格: serviceID,criteriaName,size ,价格
我的课程是:
服务,包含价格清单,以及 标准,还有包含标准名称和大小的价格和条件清单。 价格具有独特的标准和服务。还有pricePK,它具有criteriaName,size和serviceID。
我创建了primefaces向导,它具有属性widgetVar =“wiz”。最后一个问题。在dataTable中是所有条件的列表。当我检查一些标准并点击“添加服务条件”按钮时,我想要做的是选择的标准是添加到服务。
方法代码addPricesToService:
List<Prices> priceList = new LinkedList<Price>();
for (int i = 0; i < getSelectedCriteriaList().length; i++) {
Criteria criteria = getSelectedCriteriaList[i];
Price c = new Price(new PricePK(service.getPriceID(), criteria.getCriteriaPK().getCriteriaName(), criteria.getCriteriaPK().getSize()));
c.setPrice(0);
priceList.add(c);
}
service.setPriceList(priceList);
我得到的只是一个例外:
SEVERE: Received 'java.lang.NullPointerException' when invoking action listener '#{kuBean.dodajCeneUsluzi}' for component 'j_idt46'
SEVERE: java.lang.NullPointerException
at util.ServiceCreatingManager.addPricesToService(ServiceCreatingManager.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:772)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIData.broadcast(UIData.java:912)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:943)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of APPLY_REQUEST_VALUES 2 : UIComponent-ClientId=formaKreiranjeUsluge:tabelaKriterijuma, Message=java.lang.NullPointerException
SEVERE: java.lang.NullPointerException
javax.faces.event.AbortProcessingException: java.lang.NullPointerException
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:772)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIData.broadcast(UIData.java:912)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:943)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at util.ServiceCreatingManager.addPricesToService(ServiceCreatingManager.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
... 34 more
显然没有选择任何内容,这就是抛出nullPointerException的原因。有帮助吗? 附:如果有些事情难以理解,我会解释更多。
答案 0 :(得分:0)
这可能是问题所在:
<p:dataTable value="#{kuBean.service.pricesList}" var="price">
从您的代码提取中可以看出,priceList是一个List。
List<Prices> priceList = new LinkedList<Price>();
...
service.setPriceList(priceList);
您所要做的就是将服务中的priceList从“List priceList”对象更改为数组对象,例如“Price [] priceList”。