【问题标题】:JSF Exception Tags not rendered on pageJSF 异常标记未在页面上呈现
【发布时间】:2013-05-17 12:07:35
【问题描述】:

我创建了一个示例 JSF 项目并尝试在 tomcat 6 中运行,但在页面显示时出现错误。我是 JSF 的新手。我还尝试将文件名更改为 html 和欢迎列表以显示 login.html 但 JSF 标记未呈现在我的页面上

login.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title> Insert title here</title>
</head>
<body>
<f:view>
    <h:form>
        <table>
            <tr>
                <td>User Name</td>
                <td><h:inputText value="#{user.name}"></h:inputText></td>
            </tr>
        </table>
    </h:form>
</f:view>
</body>
</html>

我的web.xml如下图

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ivr</display-name>
<welcome-file-list>
    <welcome-file>login.html</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.application.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>

还有 faces-config 文件

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>com.ivr.User</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>

例外:

Class com.sun.facelets.FaceletViewHandler is no javax.faces.application.ViewHandler
Caused by:java.lang.IllegalArgumentException - Class com.sun.facelets.FaceletViewHandler is no javax.faces.application.ViewHandler

如果我将 login.xhtml 重命名为 login.html 并将欢迎文件列表更改为 login.html 异常消失但我看不到我的在我的页面上呈现的 JSF 标记。

【问题讨论】:

  • 如果我将 login.xhtml 重命名为 login.html 并将欢迎文件列表更改为 login.html 异常消失但我看不到我的页面上呈现的 JSF 标记 那是因为Faces Servlet 永远不会处理视图。您是否使用 Mojarra 或 MyFaces 作为 JSF 实现?
  • @Luiggi:&lt;listener&gt; 条目以及 OP 在成功解析 faces-config.xml 时成功启动 web 应用程序的事实表明 MyFaces。

标签: jsf jsf-1.2


【解决方案1】:

com.sun.facelets.FaceletViewHandler 类没有 javax.faces.application.ViewHandler

这表明您正在使用捆绑了 Facelets 的 JSF 2.x,但仍在尝试手动捆绑/注册专为 JSF 1.x 设计的 Facelets 1.x。

删除所有 Facelets 1.x 工件,包括 jsf-facelets.jar、&lt;view-handler&gt;、所有 &lt;context-param&gt; 条目以及 &lt;listener&gt;。使用 JSF 2.x 时不需要它们。您可能在不小心阅读 JSF 1.x 书籍/教程/资源而不是 JSF 2.x 目标时添加了它们。

然后,确保您的物理 Facelet 文件具有 .xhtml 扩展名,并且欢迎文件也指向该扩展名。最后但同样重要的是,修复您的 faces-config.xml 根声明以符合 JSF 2.0。

在继续学习 JSF 之前,我强烈建议您查看您的书籍/教程/资源,如果它们确实是针对 JSF 2.x 的。 Our JSF wiki page 是一个很好的起点。

【讨论】:

  • 请注意,faces-config.xml 文件也指向 JSF 1.2。
  • 感谢您的更新。我在我的库路径中使用 jsf 1.2(Apache MyFaces JSF Core 1.2 API 1.2.9) jar
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-20
  • 2011-03-20
  • 2012-12-08
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多