【问题标题】:MyFaces hellow world application give NullPointerException errorMyFaces 地狱世界应用程序给出 NullPointerException 错误
【发布时间】:2014-02-03 10:48:05
【问题描述】:

我是 Java 的初学者(在 2 周的阅读中),我想通过使用 Eclipse IDE 创建的项目来了解更多信息。我正在使用什么: - Java JDK 1.7 - Eclipse IDE 朱诺 - 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>

【问题讨论】:

  • 我强烈建议选择另一个示例项目。您现在手头的版本是 J2EE 1.4 + JSF 1.1 + Facelets 1.0 风格(从 ~2006 年开始)。但是,您手头的目标容器是 Java EE 6/7 + JSF 2.1/2.2 风格的。服务器运行时类路径中较新的 Facelets API 导致了这些冲突。停止阅读 JSF 1.x 教程/资源/书籍,扔掉那个遗留示例项目,专注于不超过 3 年的 JSF 2.x 教程/资源/书籍。我们的 JSF wiki 页面是一个很好的起点;将[jsf]标签悬停在问题下方,然后点击info链接。
  • @BalusC - 感谢您的意见。经过大量研究后,我还意识到生成的模板适用于旧版本的 JSF。我将它升级到 2.*,经过一些返工和错误,我设法显示了该页面。我还阅读了 JSF wiki 页面,它非常好。谢谢。
  • 我把它作为答案转发了。

标签: java jsf facelets


【解决方案1】:

您的具体问题本质上是由将 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 是一个很好的起点。

【讨论】:

    【解决方案2】:

    解决了我的问题:

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

    1. 从 war 中排除 jsf-api.jar、jsf-impl.jar 和 jstl.jar;(或 pom.xml 中的 >)
    2. 将 jsf-facelets.jar v1.1.14 替换为 v1.1.15B1(Jboss 社区和 Facelets 项目的耻辱)

    【讨论】:

    • 这永远不能成为 JSF 2.0 项目的答案.... jsf-facelets.jar 不需要在那里!!!!
    • 查看已接受答案的第一行:“您的具体问题本质上是由将 Facelets 1.x 风格的 Web 应用程序部署到 Facelets 2.x 风格的目标容器引起的。”我>
    猜你喜欢
    • 2014-12-12
    • 1970-01-01
    • 2012-09-15
    • 2013-11-10
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2011-08-04
    • 2013-01-03
    相关资源
    最近更新 更多