0

Getting HTTP Session in JSF


Here is a way to get HttpSession...

import javax.faces.context.FacesContext;
// …..
public void addInSession() {
MySession mySession = new MySession();
mySession.setName(getMsg());
/* .getSession(bool), true if we want to create new session, if want to
use old
session then false
*/
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
session.setAttribute(”sessionObj”, mySession);
if (session.getAttribute(”sessionObj”) != null) {
MySession mySavedSession = (MySession) session.getAttribute(”sessionObj”);
System.out.println(”HTTP Session: ” + mySavedSession.getName());
} else {
// do something
}
}

|

0 Comments

Copyright © 2009 So That I Can Remember All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.