0

我在确认对话框中有一个数据表,我尝试在其上放置多个选择复选框,但导致错误和数据不可见

页:

<h:form>
<p:commandButton update="msgfiles" actionListener="#{globalCounter.reloadList()}"
   oncomplete="choose.show()"/>

                <p:confirmDialog widgetVar="choose">
                    <p:dataTable id="msgfiles" var="obj" rows="5" value="#{globalCounter.objectList}"
                                 rowKey="#{obj[0]}" selection="#{globalCounter.selectedObjectList}">
                        <p:column selectionMode="multiple"/>
                        <p:column headerText="id">
                            <h:outputText value="#{obj[0]}"/>
                        </p:column>
                        <p:column headerText="name">
                            <h:outputText value="#{obj[1]}"/>
                        </p:column>
                    </p:dataTable>
                </p:confirmDialog>
            </h:form>

豆:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "globalCounter")
@SessionScoped
public class TestBean implements Serializable {

   private List<Object[]> objectList;
   public List<Object[]> getObjectList() {
        return objectList;
    }
   public void setObjectList(List<Object[]> objectList) {
        this.objectList = objectList;
    }

    public void reloadList() {
        objectList = new ArrayList<Object[]>();
        objectList.add(new Object[]{"1", "one"});
        objectList.add(new Object[]{"2", "two"});
        objectList.add(new Object[]{"3", "three"});
        objectList.add(new Object[]{"4", "four"});
        objectList.add(new Object[]{"5", "five"});
    }

    private List<Object[]> selectedObjectList;
    public List<Object[]> getSelectedObjectList() {
        return selectedObjectList;
    }
    public void setSelectedObjectList(List<Object[]> selectedObjectList) {
        this.selectedObjectList = selectedObjectList;
    }
}

错误信息:

    [#|2012-10-03T16:28:36.390+0700|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=29;_ThreadName=Thread-1;|javax.faces.FacesException
   at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:86)
   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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
   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.comet.CometEngine.executeServlet(CometEngine.java:473)
   at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
   at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
   at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
   at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
   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 java.lang.reflect.Array.newArray(Native Method)
   at java.lang.reflect.Array.newInstance(Array.java:52)
   at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:53)
   at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:39)
   at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:53)
   at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:790)
   at org.primefaces.component.api.UIData.processDecodes(UIData.java:224)
   at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
   at javax.faces.component.UIForm.processDecodes(UIForm.java:216)
   at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
   at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
   at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:941)
   at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
   ... 32 more
|#]

[#|2012-10-03T16:28:36.390+0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=29;_ThreadName=http-thread-pool-8080-(1);|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
   at java.io.Writer.write(Writer.java:140)
   at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
   at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:119)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
   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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
   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.comet.CometEngine.executeServlet(CometEngine.java:473)
   at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
   at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
   at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
   at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
   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)
|#]

[#|2012-10-03T16:28:36.390+0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=29;_ThreadName=http-thread-pool-8080-(1);|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
   at java.io.Writer.write(Writer.java:140)
   at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
   at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:119)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
   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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
   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.comet.CometEngine.executeServlet(CometEngine.java:473)
   at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
   at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
   at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
   at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
   at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
   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)
|#]

如果我<p:column selectionMode="multiple" style="width:18px" />从页面中删除一切都很好并显示数据

我哪里做错了?

Primefaces 3.4/Mojarra 2.0.2 (FCS b10)/Glassfish 3.0.1

4

3 回答 3

1

我有同样的问题,我使用<h:form>和解决了它<p:ajax>

<p:dataTable id="msgfiles" var="obj" rows="5" value="#{globalCounter.objectList}" rowKey="#{obj[0]}" selection="#{globalCounter.selectedObjectList}">
    <p:ajax event="rowSelectCheckbox" process="@this"/>
    <p:ajax event="rowUnselectCheckbox" process="@this"/>
    <p:ajax event="toggleSelect" process="@this"/>
</p:dataTable>

这应该强制您的组件在您的 bean 中填充数组

于 2013-01-31T10:11:52.133 回答
1

我有类似的问题,我使用<p:ajax>.

首先,我会按照 akoskm 所说的那样做,并拥有一个唯一的行键。

然后我会为 selectedItems 使用一个数组 (List[])(List 比 ArrayList 更通用)

最后你可以添加:

<p:dataTable ...>
    <p:ajax event="rowSelectCheckbox" process="@this"/>
    <p:ajax event="rowUnselectCheckbox" process="@this"/>
    <p:ajax event="toggleSelect" process="@this"/>
</p:dataTable>

只要确保你有一个<h:form>在桌子周围

这将确保组件将数据推送到 bean。

于 2014-07-24T15:49:34.893 回答
0

您的问题与此问题非常相似: Primefaces datatable: Unable to retrieve selected rows and selection get lost with pagination。我会尝试 rowKey="#{obj}"用作键。

于 2012-10-05T20:26:21.250 回答