带复选框问题的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>

当我看代码时,我意识到任何人都不可能理解任何东西,所以我试着解释这里发生了什么。

我在数据库中有表(主键粗体):

Service: serviceID, serviceName

标准:criteriaName, size, measureUnit

Price: serviceID, criteriaName, size, Price

我的类是:

Service,包含价格列表,和Criteria,也有价格列表和保存criteriaName和size的criteriaPK。价格有独特的标准和服务。也有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的原因。任何帮助吗?附注:如果有些事情难以理解,我将进一步解释。

问题可能出在这里:

<p:dataTable value="#{kuBean.service.pricesList}" var="price">

从你的代码摘录看来,pricesList是一个列表。

List<Prices> priceList = new LinkedList<Price>();
...
service.setPriceList(priceList);

你所要做的就是将服务中的priceList从"List priceList"对象更改为数组对象。"价格[]价格表"。

相关内容

  • 没有找到相关文章

最新更新