2011-11-17 98 views
2

嘗試通過Ajax更新頁面。點擊一個按鈕並在頁面上打印一個計數器。Oracle ADF h:commandButton f:ajax不工作

以下代碼在Tomcat 7上與JSF 2.0 mojarra一起部署時工作。從JDeveloper 11g部署到內置Weblogic服務器時,它不起作用。計數變量會增加,但每次使用ADF時都會重新加載頁面。

輔助Bean:

import javax.faces.bean.*; 
import javax.faces.event.ActionEvent; 

@ManagedBean(name="countBean") 
@SessionScoped 
public class CountBean { 
    Integer count=1; 
    public void incrementCount(ActionEvent event) { 
     ++count; 
    } 
    public Integer getCount() { return count;} 
    public void setCount(Integer count) { this.count = count; }   
} 

JSF頁面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core"> 
<h:head><title>Ajax commandButton test</title></h:head> 
<h:body> 
<h3>Ajax count</h3> 
<h:form> 
<h:commandButton id="cb" value="Increment count" 
    actionListener="#{countBean.incrementCount}"> 
    <f:ajax event="click" execute="cb" render="ot" /> 
</h:commandButton> 
<br/><br/> 
Counter = <h:outputText id="ot" value="#{countBean.count}"/> 
</h:form> 
</h:body> 
</html> 
+0

打開頁面。你是否看到兩個服務器的HTML源代碼存在差異?我*猜* jsf.js'丟失/破壞莫名其妙。 Firebug/Chrome會告訴你更多關於JS錯誤的信息。 – BalusC

回答

0

,我發現自己的答案:在瀏覽器中,右擊和*查看源文件*

<af:commandButton text="increment count" id="cb1" actionListener="#{countBean.incrementCount}" partialSubmit="true"/> 

Counter = <af:outputText id="ot" value="#{countBean.count}" partialTriggers="cb1"/>