I was expecting that whenever I click the commandLink, I'd see the bean.count property increment.
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<h:head>
<title>test page</title>
</h:head>
<h:body>
<h:form>
<h:commandLink action="#{myBean.inc}" value="Click me"/><br/>
#{myBean.count}
</h:form>
</h:body>
</html>
With a bean
package com.test;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class MyBean implements Serializable{
int count=0;
public int getCount() {
return count;
}
public void inc(){
count++;
}
}
and yet, it only increments from 0 to 1 on the first click. Could anyone tell me why?