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