JSF2 Cannot reach SessionScoped bean from ViewScoped as ManagedProperty

I have a strange problem. Afaik I can insert a SessionScoped bean into the viewcoped because its wider than the other. Here is my code:

@ManagedBean @ViewScoped public class ProjectBean implements Serializable { @ManagedProperty(value="#{projectCurrentBean}") private ProjectCurrentBean currentBean; public void setCurrentBean(ProjectCurrentBean currentBean) { this.currentBean = currentBean; } @ManagedProperty(value="#{userCredentialsBean}") private UserCredentialsBean activeUser; public void setActiveUser(UserCredentialsBean activeUser) { this.activeUser = activeUser; } 

2 managed beans:

 @ManagedBean @SessionScoped public class ProjectCurrentBean implements Serializable { 

and

 @ManagedBean @SessionScoped public class UserCredentialsBean implements Serializable { 

It works fine with UserCredentialsBean, but when I put ProjectCurrentBean it fails:

 Unable to create managed bean projectBean. The following problems were found: - The scope of the object referenced by expression #{projectCurrentBean}, request, is shorter than the referring managed beans (projectBean) scope of view 

why?:)

+4
source share
1 answer

You did not declare a bean using @SessionScoped from the javax.faces.bean package , but instead from javax.enterprise.context . This does not work in combination with @ManagedBean from the javax.faces.bean package. the bean will then by default have the request and will behave like @RequestScoped .

Correct the import.

 import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean @SessionScoped public class ProjectCurrentBean implements Serializable { 
+11
source

Source: https://habr.com/ru/post/1382042/


All Articles