Primefaces dataTable 带有复选框问题
首先,代码:
<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
Criteria:criteriaName,size,measureUnit
Price:serviceID,criteriaName,size strong>,价格
我的课程是:
服务,有价格列表,以及 Criteria,还有价格列表和包含 criteriaName 和尺寸的 criteriaPK。 价格有独特的标准和服务。还有包含 criteriaName、size 和 serviceID 的 PricePK。
我创建了 primefaces 向导,其属性为 widgetVar="wiz"。最后一个问题。数据表中列出了所有标准。当我检查某些条件并单击“将条件添加到服务”按钮时,我想要做的是将选定的条件添加到服务中。
方法 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 的原因。有什么帮助吗? ps 如果有什么难以理解的地方我会解释更多。
First of all, code:
<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>
When I looked on code I realize that there is no chance anybody to understand anything, so I try to explain what's happening here.
I have tables in database (primary keys are bold):
Service: serviceID, serviceName
Criteria: criteriaName, size, measureUnit
Price: serviceID, criteriaName, size, price
My classes are:
Service, that have list of prices, and
Criteria, also have list of prices and criteriaPK that holds criteriaName and size.
Price have unique criteria and service. Also have pricePK that have criteriaName, size and serviceID.
I created primefaces wizard, that have attribute widgetVar="wiz". And finally a question. In dataTable are list of all criteria. What I want to do when I check some criteria and click on button "Add criteria to service" is that selected criteria is add to service.
Code of method 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);
What I get is just an exception:
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
It's obviously that nothing is selected and that's why nullPointerException is thrown. Any help?
p.s. If something is hard to understand I shall explain more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是问题所在:
从您的代码摘录看来,pricesList 是一个列表。
您所要做的就是将服务中的 PriceList 从“List PriceList”对象更改为数组对象,例如“Price[] PriceList”。
This might be the problem:
It seems from your code extract, that pricesList is a List.
All you have to do is change priceList in service from a "List priceList" object to an array object e.g. "Price[] priceList".