FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put( "testBean",
testBean );
TestBean testBean = (TestBean)FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().get( "testBean")
Thursday, March 19, 2009
How-to get or remove a jsf backing bean from session?
To reset session bean
FacesContext
.getCurrentInstance()
.getApplication()
.createValueBinding( "#{yourBeanName}").setValue(FacesContext.getCurrentInstance(), null );
To get session bean reference
Object obj = FacesContext
.getCurrentInstance()
.getApplication()
.createValueBinding("#{yourBeanName}")
.getValue(FacesContext.getCurrentInstance());
YourSessionBean bean = (YourSessionBean)obj;
Sunday, March 8, 2009
Prepended L in Exception
Have you ever saw an exception with L padded before a exception???
like .executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet while running an application in your application server ?
It means that this method cannot be found on server.
The solution is to restart the server...
Saturday, March 7, 2009
Getting HTTP Session in JSF
Here is a way to get HttpSession...
// …..
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
}
}