2010-07-12 15 views
1

我使用primefaces庫,這是我的jsp頁面來源:primefaces調查標籤不起作用

<%@taglib uri="http://primefaces.prime.com.tr/ui" prefix="p"%> 
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> 
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<f:view> 
<head> 
    <p:resources /> 
    <base href="<%=basePath%>"> 

    <title>My JSP 'index.jsp' starting page</title> 
</head> 

<body> 

    <h:form> 
    <h:outputText id="txt_count" value="#{counterBean.count}" /> 
    <p:poll actionListener="#{counterBean.increment}" update="txt_count" /> 
    </h:form> 

</body> 

    </f:view> 
</html> 

和我的背豆代碼:

import javax.faces.event.ActionEvent; 


public class CounterBean { 
private int count; 
public void increment(ActionEvent actionEvent) { 
count++; 
} 
//getters and setters 
public int getCount() { 
return count; 
} 
public void setCount(int count) { 
this.count = count; 
} 
} 

我的web.xml文件中如下

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>0</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
    </servlet-mapping> 
    <servlet> 
<servlet-name>Resource Servlet</servlet-name> 
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>Resource Servlet</servlet-name> 
<url-pattern>/primefaces_resource/*</url-pattern> 
</servlet-mapping> 
    <welcome-file-list> 
    <welcome-file>test.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

我的頁面正確加載,但沒有正式更新

當它被加載它說「雅虎沒有定義」,所以它不起作用。

我已經定義了資源servlet,但它不工作!

請幫幫我!

回答

3

你顯然在JSF 2.0上使用PrimeFaces 2.0。在JSF 2.0中,p:resources已棄用。您應該使用Facelets而不是JSP。如果出了什麼權,你應該已經看到了在服務器日誌中輸入以下內容:

INFO: p:resources component is deprecated and has no use in PrimeFaces 2.0 as 
     JSF 2.0 resource apis are used instead to place resources on page. 

因爲資源沒有在頁面在內,所需的JavaScript文件,不包含在生成的JavaScript代碼無法找到雅虎庫引用,因此你檢索到的JS錯誤。如果您右鍵單擊瀏覽器中的網頁並檢查生成的HTML源代碼,則應該注意到缺少<script>也包含在內。

爲了解決這個問題,轉儲 JSP永遠和去使用Facelets。它是JSP的繼承者,在將JSF帶入圖片領域時更加優越。

*.jsp文件重命名爲*.xhtml和使用下面的代碼:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:p="http://primefaces.prime.com.tr/ui"> 
    <h:head> 
     <title>My Facelets 'index.xhtml' starting page</title> 
     <base href="//#{request.serverName}:#{request.serverPort}#{request.contextPath}"></base> 
    </h:head> 
    <h:body> 
     <h:form> 
      <h:outputText id="txt_count" value="#{counterBean.count}" /> 
      <p:poll actionListener="#{counterBean.increment}" update="txt_count" /> 
     </h:form> 
    </h:body> 
</html> 

當閱讀書籍JSF /教程確保您正在閱讀的那些覆蓋JSF 2.0,而不是1.x的