java.lang.NullPointerException at com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager

谁都会走 提交于 2020-01-15 12:23:49

问题


I'm using JSF Composite Component for reuse component. However, I keep getting a null-pointer error, I follow some of the tutorial I found but none mention this problem.

The stack trace added:

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)

I'm using Netbean 8.0, and the JSF is included in a Enterprise Application project, not sure if that cause any difference from a webApplication project.

<?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>

回答1:


Try this one

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


来源:https://stackoverflow.com/questions/23452491/java-lang-nullpointerexception-at-com-sun-faces-application-view-faceletviewhand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!