这是我的看法:
<h:body>
<h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
<h:form id="test" prependId="false">
<h:commandButton value="Increase counter">
<f:ajax execute="#{user.increaseCounter()}" render="x" />
</h:commandButton>
<h:outputText id="x" value="#{user.counter}"/>
</h:form>
</h:body>
和用户.Java:
@Named
@SessionScoped
public class User implements Serializable {
private int counter;
@PostConstruct
public void postConstruct() {
counter = 0;
}
public void increaseCounter() {
counter++;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
}
所以我希望看到的是:每次我单击“增加计数器”按钮时,屏幕上都会增加一个值。
当我调试我的应用程序时,我看到计数器增加了,但是它没有被渲染。为什么会这样?