I have JSF web app on glassfish using j_security_check validation with jdbcRealm on glassfish connected to MSSQL db.
Is there any way to check for example if there exists active bean with given username?
I just want to display on the web page who is online. My guesses:
- keep variable in database and change it with login/logout. The problem rather occurs if someone didnt logout but his session expires. Than I don’t have possibility to check if he’s still logged in.
- keep boolean variable in bean and change it with login/logout. Problem is as in previous opportunity.
Is there way to change such variable while session expires? Maybe some other approach is more common?
You have the possibility by implementing a
HttpSessionListener:Where
YourUseris your session scoped JSF managed bean representing the logged-in user.Or when you’re on JSF2 (as your question history confirms), put
@PreDestroyon the logout method in the session scoped JSF managed bean representing the logged-in user:This way the method will be invoked before the bean get destroyed on session expiration.