Question

Just a doubt regarding how JSF session management works

I got a managedbean as :

@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean implements Serializable
{

        private String userName;
        //getter and setter

        private String password;
        //getter and setter

        // Getting through spring injection
        @ManagedProperty(value="#{userBO}")
        private UserBO userBO;
        //setter method

        public fetchUserDetails(){
        User  user = userBO.getUSer(this.userName);
        //some processing
        }
    // more methods
    .
    .
    .
}

So now since the bean is sessionScoped, will JSF keep my "userBO" object in the session too? I believe that variables with both the setters and getters are likely to be stored in the session. Correct me if I am wrong. Or do I have to declare "userBO" as transient so that it is ignored?

Était-ce utile?

La solution

If your session is persisted in memory between requests, any other objects it references will be kept and not be eligible for garbage collection. There is no task that walks an object's internals setting references to null. Managed properties are only evaluated when the bean is created and before it is placed into scope.

Setting userBO to transient would only have an effect if the session was serialized (via passivation to disk, via session replication, etc.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top