2010-07-12 89 views
1

我是新來的primeface。primefaces庫問題(jsf)

我試圖檢驗關於標籤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 [email protected] 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 由於事先

回答

1
java.lang.IllegalStateException: 
    Component [email protected] not expected type. 
    Expected: javax.faces.component.UIForm. Perhaps you're missing a tag? 

例外建議您在這被放置在f:view內頁已經一個h:form地方。

由於您的代碼示例看起來很好(除了醜陋的scriptbar),您可能不會運行您認爲正在運行的代碼。重做構建和部署,並檢查你是否一切正確。

+0

感謝您的回覆已被固定。但我有另一個問題 當我的網頁被加載它說「雅虎沒有定義」,它不工作。我已經定義了資源servlet和,但它不工作! – arash 2010-07-12 18:33:31

+0

這是一個新問題。你需要發佈一個新問題。不要忘記標記接受的答案。另請參閱http://stackoverflow.com/faq(並且在適用的情況下,請不要忘記接受以前的一些答案:http://stackoverflow.com/users/332289/arash) – BalusC 2010-07-12 18:58:56