Consider the following bean support:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class Counter {
int counter;
public Counter() {
this.counter = 0;
}
public void Increment() {
this.counter++;
}
public void Decrement() {
this.counter--;
}
public int getCounter() {
return this.counter;
}
}
I created a JSF page that displays the counter value and has two buttons for increasing and decreasing. It works as expected. However, when I add the annotation javax.inject.Namedto the bean, it no longer has a session. The buttons still work (the click is processed on the server side), but the counter value always remains zero. I use annotation because in my real application I need to enter other beans into this one and this annotation seems to be mandatory (please correct me if I am wrong). What is the reason for this behavior? What can I do to get around this?
source
share