1

我是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>

这是我的后台代码:[代码]

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 在此先感谢

4

2 回答 2

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),您可能没有运行您认为正在运行的代码。重做构建和部署,并检查您是否正确执行了所有操作。

于 2010-07-12T17:03:11.733 回答
1

他们在版本 3 中更改了 uri 。使用:http://primefaces.org/ui

于 2012-08-31T13:33:00.527 回答