I'm using @Viewscoped
beans in a JSF 2.1 project. The strange thing is that when I first get a page the bean is clearly initialized with all the initial parameters. But when I navigate away, to another page, even if I close the browser tab where te app is open the bean does not die. When I go back to the page that use this bean the values are the same that were modified during the utilization of this page. And more, if I open another browser like IE or Chrome, the values are still there too!!
Is behaving like a sessionscoped. Or somekind of inmortal bean , je.
The bean is annotated like this.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.springframework.stereotype.Controller;
@Controller
@ManagedBean
@ViewScoped
public class MyBean {
//the rest of the code.
}
Why this is happen? Could be springframework annotation the cause of the problem?
I found the solution. The problem was my spring annotation in the bean. I use @Controller
from Spring Framework. This annotation create a Singleton, so my backing bean, even it has @ManagedBean
and @ViewScoped
, was created only once, and was never destroyed a re-created in every view.
I deleted @Controller
and replace @Autowired
for @ManagedProperty
for the injection and now everything works as expected.
The answer in this a question help to figure out