1

我正在开发一个页面,它显示的内容datatable与 primefaces 展示中显示的内容相同。但它不像那样工作。当我运行一两行的页面时它可以工作,但是当我运行多于两行的页面时,服务器显示一个错误[如果我设置datatableeditable然后它也不起作用]。当我将 bean 设置为时问题解决session scopedrequest or view。问题是为什么它不适用于请求或视图范围?

资料来源:

页 :

                    <p:dataTable var="club" value="#{currentClubItems.clubItems}" id="clubs"
                         >

                        <p:ajax event="rowEdit" listener="#{currentClubItems.onEdit}" update=":form:messages"/>

                        <p:column headerText="Main Category" style="width:15%">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{club.mainCategory}"/>
                                </f:facet>
                                <f:facet name="input">
                                    <p:selectOneMenu value="#{club.mainCategory}" editable="true">
                                        <f:selectItems value="#{currentClubItems.categories}"
                                                       var="ct"
                                                       itemLabel="#{ct}"
                                                       itemValue="#{ct}"/>
                                    </p:selectOneMenu>
                                </f:facet>
                            </p:cellEditor>
                        </p:column>

                        <!-- other coloms-->

                        <p:column style="width:5%">
                            <p:rowEditor/>
                        </p:column>

                    </p:dataTable>

豆 :

@ViewScoped
@ManagedBean(name = "currentClubItems")
public class CLMItems implements Serializable {
    private List<ClubItem> clubItems;

    public CLMItems(){
        clubItems=new ArrayList<ClubItem>();

        ClubItem clubItem=new ClubItem();
        clubItem.setId("1");
        clubItem.setMainCategory("category");
        clubItem.setSubCategory("sub category");
        clubItem.setMerchant("Merchant");
        clubItem.setOffer("Content goes here..");

        //add more items......
}

//getters and setters

}

俱乐部物品:

public class ClubItem implements Serializable {

    private String id;
    private String mainCategory;
    private String subCategory;
    private String merchant;
    private String offer;

 //getters and setters

}

错误 :

java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2705)
    at org.apache.catalina.connector.Request.getSession(Request.java:2231)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:899)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
    at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
    at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    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:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)
4

1 回答 1

0

如果我们要向表中添加多于两行的行,这似乎必须创建primefaces 需要创建会话。如果我在been 的构造函数中或之前激活会话,那么它可以正常工作。我没有原因,但它发生了。

添加

 //bean constructor
 public CLMItems(){
FacesContext.getCurrentInstance().getExternalContext().getSession( true );
// other stuff
}

解决这个问题。

于 2013-03-07T08:14:44.040 回答