What is the difference between the following methods?

Asked

Viewed 192 times

2

I am developing a JSF application and came across the following methods and want to know the difference between them.

((HttpSession)FacesContext.getCurrentInstance()
                     .getExternalContext().getSession(false)).invalidate();

and

FacesContext.getCurrentInstance().getExternalContext().invalidateSession();

1 answer

2


The two snippets of code perform the same action, which is to invalidate a session.
The difference is in which class the method comes from. The invalidate originate in the class HttpSession, already the invalidateSession is of class ExternalContext.
Note that in the code snippet you use the invalidate you’re making a casting of the session recovered from the FacesContext for HttpSession and thus being able to access the method.
It is interesting to add that the implementation of invalidateSession, will only execute the invalidate of HttpSession.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.