I have a @ManagedBean in my app, with the @sessionScoped anotation.
The problem is that the public no arg constructor is being called for each request, so my fields are being reseted and my model logic goes to space.
I tried build and clean, reset glassFish, but still the bean constructor get’s called at each request.
I also have a faces-config.xml to control the page navigation.
I could solve this by redeclaring the bean inside the faces-config, now it work’s…
Any ideas of why that’s happening? If i delete the faces-config, the problem persists.
Thanks everybody!
That can happen if
@SessionScopedis not of thejavax.faces.beanpackage, but instead of a completely different API, for example thejavax.enterprise.contextpackage. Doublecheck your imports and be careful with IDE autocompletion. IDEs tend to sort autosuggestions by package name and thus thejavax.enterprise.contextwould appear as 1st option.If you aren’t using any
javax.faces.beanscope annotation on a@ManagedBean, then the bean will default to@NoneScoped, which means that it’s constructed on every single#{bean}EL evaluation.See also: