JSF 标记 (xHTML) 在浏览器上未呈现为 HTML
JSF tags (xHTML) are not rendered as HTML on browser
我正在尝试使用 spring 启动来执行 JSF Primefaces
HTML 页工作正常。
但是 xHTML 页面没有呈现为 HTML。如果我在浏览器上按 F12,我会看到 JSF 标签。
我看过:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
- 我看到 URL 匹配 FacesServlet 映射:看看下面我的 Web.xml
- XML 命名空间适用于 JSF 2.2:查看我的 Web.xml 和下面的网页
最后一个不太确定:
"Multiple JSF implementations have been loaded"
在我的库中,我看到“Maven:org.glassfish.jaxb:txw2:2.3.3”和“Maven:org.glassfish:jakarta.el:3.0.3”以及tomcat。我没有添加任何一个,而且我无法从 IntelliJ IDE 的项目结构中删除它们:
这是我的 pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>caom.test</groupId>
<artifactId>motive</artifactId>
<version>0.0.1</version>
<name>TestApp</name>
<description>Motive WebApp for Propositom project</description>
<properties>
<java.version>14</java.version>
<servlet.version>3.1.0</servlet.version>
<jsf.version>2.2.8</jsf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.18.Final</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.4.0-M1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.18.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是我的 Web.xML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<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>
<welcome-file-list>
<welcome-file>/WebPage/Welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
面孔-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2">
</faces-config>
这是我的网页
<!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:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/templates/WebPageTemplate.xhtml">
<ui:param name="pageTitle" value="Home"/>
<ui:define name="Header">
<title> home | Motive</title>
</ui:define>
<ui:define name="MainBody">
<h3><strong>This is HTML</strong></h3>
<p>And it is sowing</p>
<h:outputText value="This is JSF, and it is not sowing"/>
</ui:define>
</ui:composition>
</html>
我什至重新创建了项目,以防我有一些隐藏的错误配置。
如果您不知道答案,但可以向我指出一个很好的教程,介绍如何设置它,甚至如何跟踪渲染。那会很棒!!!
将此添加到您的模板
<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:ui="http://xmlns.jcp.org/jsf/facelets">
这是给你的 webpage.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/templates/WebPageTemplate.xhtml">
也尝试更改路径 template="/WEB-INF/templates/WebPageTemplate.xhtml"
不知道这样能不能解决你的问题,可能是多种因素造成的。
所以我最终删除了 WEB-INF 并使用了 JoinFaces 4.3
这是一个 github 样例代码:
我正在尝试使用 spring 启动来执行 JSF Primefaces HTML 页工作正常。
但是 xHTML 页面没有呈现为 HTML。如果我在浏览器上按 F12,我会看到 JSF 标签。
我看过: JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
- 我看到 URL 匹配 FacesServlet 映射:看看下面我的 Web.xml
- XML 命名空间适用于 JSF 2.2:查看我的 Web.xml 和下面的网页
最后一个不太确定:
"Multiple JSF implementations have been loaded"
在我的库中,我看到“Maven:org.glassfish.jaxb:txw2:2.3.3”和“Maven:org.glassfish:jakarta.el:3.0.3”以及tomcat。我没有添加任何一个,而且我无法从 IntelliJ IDE 的项目结构中删除它们: 这是我的 pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>caom.test</groupId>
<artifactId>motive</artifactId>
<version>0.0.1</version>
<name>TestApp</name>
<description>Motive WebApp for Propositom project</description>
<properties>
<java.version>14</java.version>
<servlet.version>3.1.0</servlet.version>
<jsf.version>2.2.8</jsf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.18.Final</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.4.0-M1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.18.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是我的 Web.xML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<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>
<welcome-file-list>
<welcome-file>/WebPage/Welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
面孔-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2">
</faces-config>
这是我的网页
<!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:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/templates/WebPageTemplate.xhtml">
<ui:param name="pageTitle" value="Home"/>
<ui:define name="Header">
<title> home | Motive</title>
</ui:define>
<ui:define name="MainBody">
<h3><strong>This is HTML</strong></h3>
<p>And it is sowing</p>
<h:outputText value="This is JSF, and it is not sowing"/>
</ui:define>
</ui:composition>
</html>
我什至重新创建了项目,以防我有一些隐藏的错误配置。
如果您不知道答案,但可以向我指出一个很好的教程,介绍如何设置它,甚至如何跟踪渲染。那会很棒!!!
将此添加到您的模板
<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:ui="http://xmlns.jcp.org/jsf/facelets">
这是给你的 webpage.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/templates/WebPageTemplate.xhtml">
也尝试更改路径 template="/WEB-INF/templates/WebPageTemplate.xhtml"
不知道这样能不能解决你的问题,可能是多种因素造成的。
所以我最终删除了 WEB-INF 并使用了 JoinFaces 4.3 这是一个 github 样例代码: