[英]PrimeFaces Not Rendering
在我的maven項目中,我創建了一個“index.xhtml”文件。 當我構建並運行項目時,Web瀏覽器沒有顯示任何內容。 當我查看源代碼時,我仍然可以看到源代碼,而不是普通的html標記。
我試過通過以下方式創建XHTML文件:
上述方法均無效。
Maven POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProfitV10</groupId>
<artifactId>ProfitV10</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProfitV10</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:spinner />
</h:body>
</html>
這是第一種情況。 第二種情況,我已經有了一個運行PrimeFaces的NetBeans Web應用程序項目。 “index.html”確實呈現了。 但是當我創建一個新的JSF頁面並包含PrimeFaces命名空間時, xmlns:p="http://primefaces.org/ui"
,但是這個特殊的JSF和其他新創建的JSF頁面將不會呈現。
一定是我想念的東西,但我不知道是什么。
我的環境如下:
謝謝。
由於您使用/index.xhtml
作為歡迎文件,因此您還應該將FacesServlet映射到該擴展名。
如果您不需要現有的前綴映射,請將其替換為:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
否則只需添加*.xhtml
模式,這意味着您將最終得到:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
請注意,您幾乎總是希望在那里使用*.xhtml
映射,以防止將Facelets的源代碼暴露給公眾。
更新:
關於.jsf和.xhtml之間的區別:
.jsf
是默認映射之一(如果你沒有在JSF 2.1中聲明FacesServlet,你會得到這個)。 它源於磁盤上物理文件的擴展名(.jsp或.xhtml)與URL中使用的擴展名之間的差異。
不幸的是,這些在歷史上是不同的,因為JSF是一種附加技術,必須通過一個單獨的顯式Servlet(Faces Servlet)。純JSP從來沒有這個限制,因為它更多的內置。 JSF頁面最初只在JSP中創作,因此如果您在URL請求中使用了.jsp,則容器將直接轉到JSP並跳過Faces Servlet。
因此,必須為此發明一種解決方法,即將Faces Servlet映射到*.jsf
,然后Faces Servlet將指向JSP文件,該文件仍然在磁盤上具有擴展名.jsp
。
我個人認為一個簡單的*.xhtml
到*.xhtml
映射是唯一理智的開箱即用選項,但由於向后兼容性,似乎JSF不能再將其設置為默認值。
嘗試將primefaces.jar文件放在WebContent / WEB-INF / lib下,然后將此jar添加到構建路徑
添加另一個servlet映射:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
之后使用以下URL: http:// [HOST]:[PORT] / [WEBAPP] / faces / index。 jsf ( .jsf和NOT .xhtml)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.