Meaningless Drivel is fun!*
The moose likes JSF and the fly likes clear session scoped variable values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "clear session scoped variable values" Watch "clear session scoped variable values" New topic
Author

clear session scoped variable values

sri pathi
Greenhorn

Joined: Jul 15, 2008
Posts: 28
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

Joined: Aug 18, 2008
Posts: 598

This may help you.

web page


My Blog SCJP 5 SCWCD 5
sri pathi
Greenhorn

Joined: Jul 15, 2008
Posts: 28
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

Joined: Jul 19, 2008
Posts: 12
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

Joined: Sep 27, 2004
Posts: 114
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clear session scoped variable values
 
Similar Threads
Dealing with backing bean on request scope ?
URGENT Help Needed ...!!
How to update Session variable with Form Data ?
Moving a bean from request to session context
Submitted Form values are repeated across