PrimeFaces 3.0.M4 <p:celleditor> NullPointerException </p:celleditor>

时间:2011-11-22 22:18:50

标签: java primefaces nullpointerexception

这是我的页面:

<html xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
    <h:form>
        <p:dataTable value="#{testBean.testList}" var="test">
            <p:column>
                <h:outputText value="#{test}" />
            </p:column>
        </p:dataTable>
    </h:form>
</h:body>
</f:view>
</html>

这是我的页面不起作用:

<html xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
    <h:form>
        <p:dataTable value="#{testBean.testList}" var="test">
            <p:column>
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{test}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{test}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column>
                <p:rowEditor />
            </p:column>
        </p:dataTable>
    </h:form>   
</h:body>
</f:view>
</html>

以下是我收到的错误:

Nov 22, 2011 10:17:05 PM org.apache.myfaces.renderkit.ErrorPageWriter handleThrowable
SEVERE: An exception occurred
javax.faces.FacesException: java.lang.NullPointerException
at     org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:258)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
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:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at javax.faces.component.UIData.restoreDescendantComponentStates(UIData.java:718)
at javax.faces.component.UIData.restoreDescendantComponentStates(UIData.java:729)
at javax.faces.component.UIData.restoreDescendantComponentStates(UIData.java:729)
at javax.faces.component.UIData.setRowIndexWithoutPreserveComponentState(UIData.java:580)
at javax.faces.component.UIData.setRowIndex(UIData.java:500)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:604)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:227)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:205)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:97)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
at javax.faces.component.UIData.encodeEnd(UIData.java:1416)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:672)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1483)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
at     org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
... 17 more

当我把单元格编辑器放入其中时,似乎只会发生这种情况。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您不能以这种方式更改列表成员值:

<p:inputText value="#{test}" style="width:100%" />

您应该将inputText值分配给bean成员/变量,然后将其添加到列表中......或者更好,work with objects。 但是我尝试了你的代码并且我没有收到任何错误(不起作用但没有错误),尽管我使用的是Mojarra而不是MyFaces。