繁体   English   中英

JSF 标签 (xHTML) 在浏览器上未呈现为 HTML

[英]JSF tags (xHTML) are not rendered as HTML on browser

我正在尝试用 spring 引导 Z4C4AD5FCA2E7A3FAA474DBB1CED003 页面做 JSF Primefaces 工作正常。

但 xHTML 页面不会呈现为 HTML。 如果我在浏览器上按 F12,我会看到 JSF 标签。

我看过: JSF 返回空白/未解析页面,带有普通/原始 XHTML/XML/EL 源而不是呈现的 HTML output

  • 我看到 URL 匹配 FacesServlet 映射:看看我的 Web.xml 下面
  • XML 命名空间用于 JSF 2.2:看看我的 Web.Z0F635D0E10F38274FFF8 网页下面

我不太确定最后一个:

“已加载多个 JSF 实现”

在我的图书馆中,我看到“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">

也尝试改变路径模板=“/WEB-INF/templates /WebPageTemplate.xhtml

我不知道这是否会解决您的问题,这可能是由多种因素引起的。

所以我最终删除了 WEB-INF 并使用 JoinFaces 4.3 这里是一个 github 就像一个示例代码:

连接面示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM