Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clear session scoped variable values

 
sri pathi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a problem now. My application has a sequence of 7 screens and at the end of 7th screen there is a Submit link which saves the values to database. I have the managed bean for all the pages in session scope so that the form retains the values even after the user navigates to say 6th page and comes back to first page. So now when the user submit the values finally I would like to clear the managed bean values in the session scope. Each managed bean has about 10 - 20 fields.
Is there an efficient way to do this? Any input would be greatly appreciated.
Thanks everyone for your time.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may help you.

web page
 
sri pathi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link looks like what I wanted to do, but I could not get it to work.
I even tried to get the values from session map by using FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("ManagedBeanClassName")
Is that how we get an item from a session map?
 
prasad kolla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be some thing like this. you can remove the mpb from the session, bean name will be the one you specify in your faces-config.xml.

Class.setVariableValue("#{" + beanName + "}", null);

public static void setVariableValue(String facesVarName, Object newValue) {
FacesContext ctx = getFacesContext();
ValueBinding bind = ctx.getApplication().createValueBinding(facesVarName);

Class bindClass = bind.getType(ctx);
if(!bindClass.isPrimitive())
{
if(newValue == null || bindClass.isInstance(newValue))
bind.setValue(ctx, newValue);
}
else
bind.setValue(ctx, newValue);
}
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have some resetting methods in each managed bean and call each one of them on click of Submit. You should be able to access one managed bean from another. I dont know if this is a good practice, but every property that I have in a managed bean, I also have it in the reset method of the managed bean.
But do consider where the submit button should take to; will it still be showing the data present on these 7 pages?
If this is the case you are better off calling those reset methods while navigating away from these 7 pages(like back to Main Menu or some other unrelated page). As an alternate, you could also call these reset methods at the time of starting the 7 pages workflow.

Note that above methods only reset the properties in the managed bean; the managed bean itself will still be in session.
[ December 02, 2008: Message edited by: A. Dusi ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic