尝试通过Ajax更新页面。单击按钮并在页面上打印出计数器。
以下代码在Tomcat 7上使用JSF 2.0 mojarra进行部署时有效。从JDeveloper 11g部署到内置Weblogic服务器时,它不起作用。 count变量确实会增加,但每次使用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 :(得分:0)
我自己找到了答案:
<af:commandButton text="increment count" id="cb1" actionListener="#{countBean.incrementCount}" partialSubmit="true"/>
Counter = <af:outputText id="ot" value="#{countBean.count}" partialTriggers="cb1"/>