【问题标题】:primefaces poll tag does not workprimefaces 投票标签不起作用
【发布时间】:2010-07-12 20:08:22
【问题描述】:

我正在使用 primefaces 库这是我的 jsp 页面源代码:

<%@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>

而我的后台 bean 代码是:

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,但它还不能工作!

请帮帮我!

【问题讨论】:

    标签: jsf tags primefaces


    【解决方案1】:

    您显然是在 JSF 2.0 上使用 PrimeFaces 2.0。 p:resources 在 JSF 2.0 中被弃用。您应该使用 Facelets 而不是 JSP。如果一切正常,您应该在服务器日志中看到以下条目:

    INFO: p:resources 组件已弃用,在 PrimeFaces 2.0 中没有用
          而是使用 JSF 2.0 资源 API 在页面上放置资源。
    

    由于页面中没有包含资源,因此没有包含所需的 JavaScript 文件,并且生成的 JavaScript 代码找不到 Yahoo 库引用,因此您检索到的 JS 错误。如果您在浏览器中右键单击该网页并检查了生成的 HTML 源代码,您应该已经注意到缺少 &lt;script&gt; 包含。

    要解决此问题,请永远转储 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 的书籍。

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多