Reputation: 1206
this is a theoretical question...
Every example i have looked at uses the @SessionScoped for log in examples, The log in bean is saved in the session even if the credentials are not correct.
If the user does not log in the bean is saved in the session, but the "user" object itself inside the log in bean will be null, thus it's easy to impelemnt an isLoggedIn() method.
Is this the way to go? Or should the bean be saved in the session ONLY if the credentials are correct?
I was thinking that for every visit in the log in page it will cause a session bean to be stored even if the user does not log in.
Upvotes: 1
Views: 426
Reputation: 1109635
You can manually put an unmanaged bean in session by ExternalContext#getSessionMap()
.
externalContext.getSessionMap().put("user", user);
It's also available by #{user}
in EL. Which way the best is, is up to you. With a managed bean you can ensure that the #{user}
is never null
. With an unmanaged bean, you've to check everytime if #{user}
is not null
before accessing anything. But if you need to postpone unnecessary session creation as much as possible, then it would make sense to use an unmanaged bean.
Upvotes: 2