MyFaces hellow world应用程序出现NullPointerException错误

时间:2014-02-03 10:48:05

标签: java jsf facelets

我是Java的初学者(阅读2周后),我想通过使用Eclipse IDE创建的项目来学习更多知识。我在用什么: - Java JDK 1.7 - Eclipse IDE Juno - Maven最新版本 - JBoss(7.1.1,6.2 EAP,WidlFly) - 都具有相同的行为 - 使用Maven原型创建的maven项目:myfaces-archetype-helloworld-facelets。

尝试运行时,我在页面中收到java.lang.NullPointerException。来自JBoss的日志显示:

 12:25:58,890 INFO  [org.apache.catalina.core] (ServerService Thread Pool -- 33) JBWEB001093: The listener org.apache.myfaces.webapp.StartupServletContextListener is already configured for this context, the duplicate definition has been ignored
    12:25:58,907 INFO  [org.apache.myfaces.shared_impl.config.MyfacesConfig] (ServerService Thread Pool -- 33) No context init parameter 'org.apache.myfaces.RENDER_VIEWSTATE_ID' found, using default value true
    12:25:58,907 INFO  [org.apache.myfaces.shared_impl.config.MyfacesConfig] (ServerService Thread Pool -- 33) No context init parameter 'org.apache.myfaces.STRICT_XHTML_LINKS' found, using default value true
    12:25:58,907 INFO  [org.apache.myfaces.shared_impl.config.MyfacesConfig] (ServerService Thread Pool -- 33) No context init parameter 'org.apache.myfaces.CONFIG_REFRESH_PERIOD' found, using default value 2
    12:25:58,907 INFO  [org.apache.myfaces.shared_impl.config.MyfacesConfig] (ServerService Thread Pool -- 33) No context init parameter 'org.apache.myfaces.VIEWSTATE_JAVASCRIPT' found, using default value false
    12:25:58,908 INFO  [org.apache.myfaces.shared_impl.config.MyfacesConfig] (ServerService Thread Pool -- 33) Starting up Tomahawk on the MyFaces-JSF-Implementation
    12:25:58,919 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) Reading standard config META-INF/standard-faces-config.xml
    12:25:58,972 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) Reading config vfs:/D:/JBoss/jboss-eap-6.2/standalone/deployments/test.war/WEB-INF/lib/jsf-facelets-1.1.11.jar/META-INF/faces-config.xml
    12:25:58,976 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) Reading config vfs:/D:/JBoss/jboss-eap-6.2/standalone/deployments/test.war/WEB-INF/lib/tomahawk-1.1.5.jar/META-INF/faces-config.xml
    12:25:58,997 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) Reading config /WEB-INF/examples-config.xml
    12:25:59,005 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) MyFaces-package : myfaces-api not found.
    12:25:59,005 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) MyFaces-package : myfaces-impl not found.
    12:25:59,005 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) MyFaces-package : tomahawk-sandbox not found.
    12:25:59,005 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) MyFaces-package : tomahawk not found.
    12:25:59,012 WARN  [org.apache.myfaces.shared_impl.util.LocaleUtils] (ServerService Thread Pool -- 33) Locale name in faces-config.xml null or empty, setting locale to default locale : en_US
    12:25:59,137 INFO  [org.apache.myfaces.config.FacesConfigurator] (ServerService Thread Pool -- 33) Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
    12:25:59,144 INFO  [org.apache.myfaces.webapp.AbstractFacesInitializer] (ServerService Thread Pool -- 33) ServletContext 'D:\JBoss\jboss-eap-6.2\standalone\deployments\test.war\' initialized.
    12:25:59,201 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018565: Replaced deployment "test.war" with deployment "test.war"
    12:26:09,185 SEVERE [facelets.compiler] (http-localhost/127.0.0.1:8080-1) Missing Built-in Tag Libraries! Make sure they are included within the META-INF directory of Facelets' Jar
    12:26:09,207 SEVERE [facelets.viewhandler] (http-localhost/127.0.0.1:8080-1) Error Rendering View[/helloWorld.xhtml]: java.lang.NullPointerException


    Below is the entire stacktrace:
    java.lang.NullPointerException
        at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
        at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
        at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
        at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:510)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:553)
        at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
        at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920)
        at java.lang.Thread.run(Thread.java:744)

从我的研究中,一个潜在的问题是这个原型项目试图覆盖JBoss中已经存在的现有facelets实现。这是JBoss 7.1中的一个问题,但同样的错误也出现在7.2(6.2 EAP)中。 PS项目正在使用:WAR_BUNDLES_JSF_IMPL。

pom文件位于下方。

<?xml version="1.0"?>

<!--
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <description>MyProject web.xml</description>

    <context-param>
        <param-name>
            org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- Configure tomahawk taglib -->
    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/tomahawk.taglib.xml</param-value>
    </context-param>

    <!-- Use Documents Saved as *.xhtml -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <!-- Special Debug Output for Development -->
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Comma separated list of URIs of (additional) faces config
            files. (e.g. /WEB-INF/my-config.xml) See JSF 1.0 PRD2,
            10.3.2 Attention: You do not need to put
            /WEB-INF/faces-config.xml in here.
        </description>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/examples-config.xml</param-value>
    </context-param>
    <context-param>
        <description>
            State saving method: "client" or "server" (= default) See
            JSF Specification 2.5.3
        </description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). Defines the amount (default = 20) of the latest
            views are stored in session.
        </description>
        <param-name>
            org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
        </param-name>
        <param-value>20</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). If true (default) the state will be serialized to
            a byte stream before it is written to the session. If false
            the state will not be serialized to a byte stream.
        </description>
        <param-name>
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (=
            default) If true (default) the serialized state will be
            compressed before it is written to the session. If false the
            state will not be compressed.
        </description>
        <param-name>
            org.apache.myfaces.COMPRESS_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            This parameter tells MyFaces if javascript code should be
            allowed in the rendered HTML output. If javascript is
            allowed, command_link anchors will have javascript code that
            submits the corresponding form. If javascript is not
            allowed, the state saving info and nested parameters will be
            added as url parameters. Default: "true"
        </description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <description>
            If true, rendered HTML code will be formatted, so that it is
            "human readable". i.e. additional line separators and
            whitespace will be written, that do not influence the HTML
            code. Default: "true"
        </description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            If true, a javascript function will be rendered that is able
            to restore the former vertical scroll on every request.
            Convenient feature if you have pages with long lists and you
            do not want the browser page to always jump to the top if
            you trigger a link or button action that stays on the same
            page. Default: "false"
        </description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Used for encrypting view state. Only relevant for client
            side state saving. See MyFaces wiki/web site documentation
            for instructions on how to configure an application for
            diffenent encryption strengths.
        </description>
        <param-name>org.apache.myfaces.SECRET</param-name>
        <param-value>NzY1NDMyMTA=</param-value>
    </context-param>

    <context-param>
        <description>
            Validate managed beans, navigation rules and ensure that
            forms are not nested.
        </description>
        <param-name>org.apache.myfaces.VALIDATE</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Treat readonly same as if disabled attribute was set for
            select elements.
        </description>
        <param-name>
            org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Use the defined class as the class which will be called when
            a resource is added to the ExtensionFilter handling. Using
            StreamingAddResource here helps with performance. If you
            want to add custom components and want to use the
            ExtensionFilter, you need to provide your custom
            implementation here.
        </description>
        <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
        <param-value>
            org.apache.myfaces.renderkit.html.util.DefaultAddResource
        </param-value>
    </context-param>

    <context-param>
        <description>
            Virtual path in the URL which triggers loading of resources
            for the MyFaces extended components in the ExtensionFilter.
        </description>
        <param-name>
            org.apache.myfaces.RESOURCE_VIRTUAL_PATH
        </param-name>
        <param-value>/faces/myFacesExtensionResource</param-value>
    </context-param>

    <context-param>
        <description>
            Check if the extensions-filter has been properly configured.
        </description>
        <param-name>
            org.apache.myfaces.CHECK_EXTENSIONS_FILTER
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Define partial state saving as true/false.
        </description>
        <param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
        <param-value>false</param-value>
    </context-param>

    <!-- Extensions Filter -->
    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>
            org.apache.myfaces.webapp.filter.ExtensionsFilter
        </filter-class>
        <init-param>
            <description>
                Set the size limit for uploaded files. Format: 10 - 10
                bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
        </init-param>
        <init-param>
            <description>
                Set the threshold size - files below this limit are
                stored in memory, files above this limit are stored on
                disk.

                Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

    <!-- Listener, to allow Jetty serving MyFaces apps -->
    <listener>
        <listener-class>
            org.apache.myfaces.webapp.StartupServletContextListener
        </listener-class>
    </listener>

    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <!-- Welcome files -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

已编辑添加的网页代码 页面的代码非常简单。我认为是关于部署,而不是代码(见下文):

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Hello World</title>
</head>
<body>
<ui:composition template="/template.xhtml">

    <ui:define name="body">
        <h:form id="form">

        </h:form>
    </ui:define>
</ui:composition>
</body>
</html>

我也在添加web.xml,以防万一。

<?xml version="1.0"?>

<!--
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <description>MyProject web.xml</description>

    <context-param>
        <param-name>
            org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- Configure tomahawk taglib -->
    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/tomahawk.taglib.xml</param-value>
    </context-param>

    <!-- Use Documents Saved as *.xhtml -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <!-- Special Debug Output for Development -->
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Comma separated list of URIs of (additional) faces config
            files. (e.g. /WEB-INF/my-config.xml) See JSF 1.0 PRD2,
            10.3.2 Attention: You do not need to put
            /WEB-INF/faces-config.xml in here.
        </description>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/examples-config.xml</param-value>
    </context-param>
    <context-param>
        <description>
            State saving method: "client" or "server" (= default) See
            JSF Specification 2.5.3
        </description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). Defines the amount (default = 20) of the latest
            views are stored in session.
        </description>
        <param-name>
            org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
        </param-name>
        <param-value>20</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). If true (default) the state will be serialized to
            a byte stream before it is written to the session. If false
            the state will not be serialized to a byte stream.
        </description>
        <param-name>
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (=
            default) If true (default) the serialized state will be
            compressed before it is written to the session. If false the
            state will not be compressed.
        </description>
        <param-name>
            org.apache.myfaces.COMPRESS_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            This parameter tells MyFaces if javascript code should be
            allowed in the rendered HTML output. If javascript is
            allowed, command_link anchors will have javascript code that
            submits the corresponding form. If javascript is not
            allowed, the state saving info and nested parameters will be
            added as url parameters. Default: "true"
        </description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <description>
            If true, rendered HTML code will be formatted, so that it is
            "human readable". i.e. additional line separators and
            whitespace will be written, that do not influence the HTML
            code. Default: "true"
        </description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            If true, a javascript function will be rendered that is able
            to restore the former vertical scroll on every request.
            Convenient feature if you have pages with long lists and you
            do not want the browser page to always jump to the top if
            you trigger a link or button action that stays on the same
            page. Default: "false"
        </description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Used for encrypting view state. Only relevant for client
            side state saving. See MyFaces wiki/web site documentation
            for instructions on how to configure an application for
            diffenent encryption strengths.
        </description>
        <param-name>org.apache.myfaces.SECRET</param-name>
        <param-value>NzY1NDMyMTA=</param-value>
    </context-param>

    <context-param>
        <description>
            Validate managed beans, navigation rules and ensure that
            forms are not nested.
        </description>
        <param-name>org.apache.myfaces.VALIDATE</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Treat readonly same as if disabled attribute was set for
            select elements.
        </description>
        <param-name>
            org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Use the defined class as the class which will be called when
            a resource is added to the ExtensionFilter handling. Using
            StreamingAddResource here helps with performance. If you
            want to add custom components and want to use the
            ExtensionFilter, you need to provide your custom
            implementation here.
        </description>
        <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
        <param-value>
            org.apache.myfaces.renderkit.html.util.DefaultAddResource
        </param-value>
    </context-param>

    <context-param>
        <description>
            Virtual path in the URL which triggers loading of resources
            for the MyFaces extended components in the ExtensionFilter.
        </description>
        <param-name>
            org.apache.myfaces.RESOURCE_VIRTUAL_PATH
        </param-name>
        <param-value>/faces/myFacesExtensionResource</param-value>
    </context-param>

    <context-param>
        <description>
            Check if the extensions-filter has been properly configured.
        </description>
        <param-name>
            org.apache.myfaces.CHECK_EXTENSIONS_FILTER
        </param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Define partial state saving as true/false.
        </description>
        <param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
        <param-value>false</param-value>
    </context-param>

    <!-- Extensions Filter -->
    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>
            org.apache.myfaces.webapp.filter.ExtensionsFilter
        </filter-class>
        <init-param>
            <description>
                Set the size limit for uploaded files. Format: 10 - 10
                bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
        </init-param>
        <init-param>
            <description>
                Set the threshold size - files below this limit are
                stored in memory, files above this limit are stored on
                disk.

                Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

    <!-- Listener, to allow Jetty serving MyFaces apps -->
    <listener>
        <listener-class>
            org.apache.myfaces.webapp.StartupServletContextListener
        </listener-class>
    </listener>

    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <!-- Welcome files -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

2 个答案:

答案 0 :(得分:5)

您的具体问题主要是由Facelets 1.x风格的Web应用程序部署到Facelets 2.x风格的目标容器引起的。此版本不兼容导致Facelets 1.x的内部代码中的NPE,因为它并不期望在Facelets 2.x环境中运行。堆栈跟踪中的com.sun.facelets.*行确认正在使用Facelets 1.x(如果它是Facelets 2.x,应该是,那么将使用com.sun.faces.facelets.*包)。

抛弃遗留的J2EE 1.4 / JSF 1.x / Facelets 1.0风格的项目。它们完全过时,在Java EE 6/7环境中表现不佳。专注于寻找JSF 2.x项目,资源,教程和书籍。 Our JSF wiki page是一个很好的起点。

答案 1 :(得分:0)

解决了我的问题:

首先尝试使用v1.1.15B1升级jsf-facelets.jar v1.1.14,如果不起作用:

  1. 从战争中排除了jsf-api.jar,jsf-impl.jar和jstl.jar;(或者&lt;&lt;&lt;&gt;&gt;在pom.xml中)
  2. 用v1.1.15B1替换了jsf-facelets.jar v1.1.14(在Jboss社区和Facelets项目上的耻辱)