Wednesday, 15 August 2012

jsf 2 - How to clear an object of the session scoped managed bean? -



jsf 2 - How to clear an object of the session scoped managed bean? -

i developing login based application in jsf primefaces. in kept logged user info in session scoped managedbean , need clear details when logged out, how clear details in sessionscoped managedbean object?

you need invalidate current session calling next function in action method:

facescontext.getcurrentinstance().getexternalcontext().invalidatesession();

also, session scoped beans trashed buring subsequent request, sure send redirect:

facescontext.getcurrentinstance().getexternalcontext().redirect("/login.xhtml");

or, homecoming navigation case outcome method:

return "login.xhtml?faces-redirect=true";

in case don't want invalidate session and, effectively, retaining session scoped beans (which bad practice in opinion), nullify of user info (which collected in 1 session scoped managed bean) in logout method (you may need inject bean in case logout method resides in session scoped bean).

jsf-2 primefaces

No comments:

Post a Comment