I have a JSF managed bean in session scope that contains an entity to trace, for example, the authenticated user:
@ManagedBean
@SessionScoped
public class LoginController implements Serializable {
User user;
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
/* ... */
}
In another bean I have to inject the user to use it to retrieve a list of roles in association with it, like this:
@ManagedBean
@ViewScoped
public class AnotherController implements Serializable {
List<Role> roles;
@ManagedProperty(value="#{loginController.user}")
User user;
public someMethod() {
/* Some stuff that insert other roles into database, referring the user as owner */
roles = user.getRolesList();
}
}
If I update the page with ajax using someMethod
, the roles
list still not reload.
If I insert em.refresh(user)
before user.getRolesList
I get this error:
Can not refresh not managed object: model.User[ id=1 ].
Can anyone help me to understand this? Why session scoped entity get not managed if injected into another bean? How can I fix this? Thank you.