简单的primefaces应用程序无法正常工作

She*_*har 4 eclipse tomcat6 primefaces jsf-2

我正在尝试使用primefaces构建简单的JSF应用程序,但不知何故,primefaces组件无法正确呈现.我不明白出了什么问题.

我试图显示以下Facelet文件:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <link type="text/css" 
                rel="stylesheet"
                href="/Themes/primefaces-dot-luv/theme.css" />
    </h:head>
    <h:body>
        <p:spinner value="100" style="height: 10px" />
        <br/>
        <p:button value="Navigate"></p:button>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

我正在使用eclipse在tomcat服务器上运行应用程序.当我运行应用程序并在浏览器(firefox)中查看页面源时,我得到以下来源:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.prime.com.tr/ui">
    <head>
        <link type="text/css" rel="stylesheet" href="Themes/primefaces-dot-luv/theme.css" />
    </head>
    <body>
        <p:spinner value="100" style="height: 10px"></p:spinner>
        <br />
        <p:button value="Navigate"></p:button>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我认为PrimeFaces组件没有得到正确的渲染.像其他JSF标记<h:head><h:body>被正确地转换为<head><body>分别的元件.只有标记为开头的标签<p:>才会被转换.

以下是我的项目结构:

在此输入图像描述

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>HelloJSF</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>
  <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>none</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

我正在使用eclipse,tomcat服务器.JSF 2和primefaces 3库.

嗨,在对整个项目进行了一些仔细检查后,我发现从现场下载的素数罐没有任何课程.Jar本身就是腐败的.我下载了相同的jar三次然后jar也变得腐败了.所以我下载了包含源代码和二进制文件的zip文件,我的应用程序开始运行

Ala*_*ect 5

尝试更改web.xml servlet映射:

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

判断Facelets Servlet是否正在处理您的xhtml的方法是查看浏览器接收的内容.如果它看起来像你的xhtml文件,那么你有一些错误的配置.