primefaces库(jsf)的问题

时间:2010-07-12 16:53:13

标签: jsf primefaces

我是Primeface的新手。

我试图在文档中测试一个关于标记的primefaces的例子,

这是我的jsf页面代码:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@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>

 <head>

  <base href="<%=basePath%>">

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

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


</html>

这是我的backbean代码: [代码]

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;
}
}

但是当我试图运行它时。我收到了这个错误:

java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@ed32c4 not expected type.  Expected: javax.faces.component.UIForm.  Perhaps you're missing a tag?
 com.sun.faces.taglib.html_basic.FormTag.setProperties(FormTag.java:199)
 javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:586)
 javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1070)
 com.sun.faces.taglib.html_basic.FormTag.doStartTag(FormTag.java:273)
 org.apache.jsp.index_jsp._jspx_meth_h_005fform_005f0(index_jsp.java:120)
 org.apache.jsp.index_jsp._jspService(index_jsp.java:93)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:428)
 com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:444)
 com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:116)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
 com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)

有什么不对?我怎么解决呢?我正在使用tomcat 6 提前谢谢

2 个答案:

答案 0 :(得分:1)

java.lang.IllegalStateException: 
  Component javax.faces.component.UIViewRoot@ed32c4 not expected type. 
  Expected: javax.faces.component.UIForm. Perhaps you're missing a tag? 

例外情况表明,您在页面的某个位置h:form 已放置在f:view内。

由于您的代码示例看起来很好(除了丑陋的 scriptlets ),您可能无法运行您认为正在运行的代码。重做构建和部署,并检查是否正确执行了所有操作。

答案 1 :(得分:1)

版本3中的changed the uri。 使用:http://primefaces.org/ui