java.lang.NullPointerException at com.sun.faces.application.



我使用JSF复合组件来重用组件。然而,我一直得到一个空指针错误,我遵循一些教程,我发现,但没有提到这个问题。

堆栈跟踪添加:

java.lang.NullPointerException
    at com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager$ArbitraryMethodRegargetHandler.retarget(FaceletViewHandlingStrategy.java:1883)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.retargetMethodExpressions(FaceletViewHandlingStrategy.java:772)
    at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(CompositeComponentTagHandler.java:201)
    at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:190)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
    at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:190)
    at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
    at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:972)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:745)

我使用的是Netbean 8.0, JSF包含在企业应用程序项目中,不确定这是否与webApplication项目有任何区别。

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:composite="http://xmlns.jcp.org/jsf/composite"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
    </h:head>
    <h:body>
        <composite:interface>
            <composite:attribute name="action"/>
        </composite:interface>
        <composite:implementation>
        <h:form>
            <h:panelGrid columns="2">     
                <h:panelGroup>Customer Name:</h:panelGroup>
                <h:panelGroup>
                <h:inputText value="#{MyMB.customer.name}">
                    <f:validateRegex pattern="(?:[A-Za-z]+s*)+"/>
                </h:inputText>
                </h:panelGroup>
                <h:panelGroup>Address:</h:panelGroup>
                <h:panelGroup>
                <h:inputText value="#{MyMB.customer.address}"></h:inputText>
                </h:panelGroup>
                <h:panelGroup>Date Of Birth:</h:panelGroup>
                <h:panelGroup>
                    <h:inputText value="#{MyMB.customer.dateOfBirth}">
                    <f:convertDateTime pattern="MM/dd/yyyy"/>
                </h:inputText>
                </h:panelGroup>
                <h:panelGroup>Gender:</h:panelGroup>
                <h:panelGroup>
                <h:selectOneRadio value="#{MyMB.customer.gender}">
                    <f:selectItem itemValue="Male" itemLabel="Male"/>
                    <f:selectItem itemValue="Female" itemLabel="Female"/>
                </h:selectOneRadio>
                </h:panelGroup>
            </h:panelGrid>
            <h:commandButton value="Submit" action="#{cc.attrs.action}"></h:commandButton>
        </h:form>
        </composite:implementation>    
    </h:body>
</html>

Index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:comp="http://java.sun.com/jsf/composite/comp">
    <h:head>
        <title>Customers Management</title>
    </h:head>
    <h:body>
        <h:button value="Register Customer" outcome="register.xhtml"></h:button>
        <h:button value="Update Customer Info" outcome="update.xhtml"></h:button>
        <comp:customerForm action="#{MyMB.findCustomer()}"></comp:customerForm>
        <h:panelGrid columns="2">
            <h:panelGroup>
            </h:panelGroup>
            <h:panelGroup>
                <h:form>
                    <h:selectOneListbox style="margin-left: 100px; width:200px; height:120px" value="#{MyMB.customer}">
                        <f:selectItems value="#{MyMB.listOfCust}"/>
                    </h:selectOneListbox>
                    <h:commandButton value="Remove" action="#{MyMB.removeCustomer()}"></h:commandButton>
                    <h:commandButton value="Update Customer Info" action="update.xhtml"></h:commandButton> 
                </h:form>
            </h:panelGroup>
        </h:panelGrid>
    </h:body>
</html>

试试这个

<composite:attribute name="action" method-signature="java.lang.String action()"/>

相关内容

  • 没有找到相关文章