Java 未呈现 JSF 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3328959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:13:01  来源:igfitidea点击:

JSF tags not rendered

javajsffacelets

提问by user401451

I am new to JSF, but my JSF tags are not rendered in xhtml file, i tried out every possible solution, but problem is not solved

我是 JSF 的新手,但我的 JSF 标签没有在 xhtml 文件中呈现,我尝试了所有可能的解决方案,但问题没有解决

my web.xml

我的 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>JSFProject</display-name>
  <welcome-file-list>
    <welcome-file>JSFProject/index.html</welcome-file>
    <welcome-file>JSFProject/index.htm</welcome-file>
    <welcome-file>JSFProject/index.jsp</welcome-file>
    <welcome-file>JSFProject/default.html</welcome-file>
    <welcome-file>JSFProject/default.htm</welcome-file>
    <welcome-file>JSFProject/default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

  <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>
</web-app>

my example.xhtml

我的例子.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>Example</title>
</head>
<body>
 <h:form>
    Some random data: <h:inputText/><br/>  <!-- Textfield ignored -->
    Some other data: <h:inputText/><br/>   <!-- Textfield ignored -->

    </h:form>

</body>
</html>

I had spend 3 days to figure out the problem, any help will be welcome

我花了 3 天的时间来解决问题,欢迎任何帮助

回答by Jose Diaz

Try:

尝试:

<?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>Example</title>
</head>
<body>
<f:view>
 <h:form>
    Some random data: <h:inputText/><br/>  <!-- Textfield ignored -->
    Some other data: <h:inputText/><br/>   <!-- Textfield ignored -->

    </h:form>

</f:view>
</body>
</html>

I've included the JSF <f:view>tag

我已经包含了 JSF<f:view>标签

回答by BalusC

The symptoms of the JSF components not being parsed at all indicates that the FacesServlethasn't run. This will happen when the request URL doesn't match the url-patternof the FacesServletas definied in web.xml. This would mean that the actualurl-patternof the FacesServletisn't *.xhtmlat all. Are you looking into and editing the right web.xmlyou think you are? Is the right web.xmlbeen deployed with the webapp into the servletcontainer?

根本没有解析 JSF 组件的症状表明FacesServlet尚未运行。当请求URL不匹配,这会发生url-patternFacesServlet,如definied web.xml。这将意味着根本不是实际url-pattern的。您是否正在研究和编辑您认为的权利?权限是否已随 webapp 部署到 servletcontainer 中?FacesServlet*.xhtmlweb.xmlweb.xml

回答by Petar Minchev

Man, you haven't set the javax.faces.DEFAULT_SUFFIXcontext parameter. The default for jsfis jsp, so jsfwill search for example.jspinstead of example.xhtml. Basically JSFreplaces the extension of the resource requested with the javax.faces.DEFAULT_SUFFIX.

伙计,你还没有设置javax.faces.DEFAULT_SUFFIX上下文参数。默认jsf就是jsp,这样jsf将搜索example.jsp代替example.xhtml。基本上JSFjavax.faces.DEFAULT_SUFFIX.

Use the following and it will work:

使用以下内容,它将起作用:

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>

回答by Martin

Do you have faces-config.xml in place that declares Facelets as view handler?

您是否有将 Facelets 声明为视图处理程序的 faces-config.xml?

<?xml version="1.0"?>
<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">
<application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>

Don't forget about javax.faces.DEFAULT_SUFFIX parameter to be set to .xhtml as mentioned above.

不要忘记将 javax.faces.DEFAULT_SUFFIX 参数设置为 .xhtml 如上所述。

回答by Saroj Nayak

I had the same problem, I fixed this by updating below as:- Already Martin had mentioned in the above. Thanks.

我遇到了同样的问题,我通过以下更新解决了这个问题:- Martin 在上面已经提到了。谢谢。

web.xml

网页.xml

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

<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>*.faces</url-pattern>
  </servlet-mapping>

faces-config.xml

人脸配置文件

<application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>

回答by SmartCoder

Add the following in your web-inf/lib :

在您的 web-inf/lib 中添加以下内容:

jsf-api-2.0.9.jar jsf-facelets-1.1.14.jar jsf-impl-2.0.4-b09.jar jstl-1.2.jar

jsf-api-2.0.9.jar jsf-facelets-1.1.14.jar jsf-impl-2.0.4-b09.jar jstl-1.2.jar

without jsf-facelets*.jar, you won't be able to render the jsf view.

如果没有 jsf-facelets*.jar,您将无法呈现 jsf 视图。

And, following should be in your web.xml :

并且,以下应该在您的 web.xml 中:

 <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>/jsf/*</url-pattern>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

Without above two url-pattern, tomcat won't be able to map .xhtml file properly.

如果没有以上两个 url-pattern,tomcat 将无法正确映射 .xhtml 文件。

And, faces-config.xml :

而且,faces-config.xml :

<?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_2_0.xsd"
    version="2.0">

</faces-config>