File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Changing Scope dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Changing Scope dynamically" Watch "Changing Scope dynamically" New topic

Changing Scope dynamically

Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
Hi All,

I have a situation in which I have to change the scope from "request" to "session" in the action class. How could i get this functionality. I know that if i try to use the setScope method, i would get the error "configuration is freezed". What is the alternate way to achieve this. Any ideas


"Failure is not when you fall down; its only when you fail to get up again."
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

You could copy the object from the request to the session. What are you trying to do? This seems like an awkward way of doing something.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Sounds to me like he is asking how to change the scope of the action specified in the struts-config.xml. However, I am with you Jeanne. I am not sure what he is trying to do exactly or why. Maybe a bit more information about the scenerio would help.

GenRocket - Experts at Building Test Data
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
I want to set the actionform into session scope due to some specific application requirements at some point in the action class. As you said I can copy from request to session, I tried it but didn't work for me.

This is my form bean which is in request scope at action level

If you could see the forward tag for "redirect" what it does is redirects to the original page "quoteheader.jsp" after displaying some message to the user, so I am using the javascript funtion "opener.location.reload". Now the "quoteheader.jsp" woudn't get the details from the actionForm as it a different request.

It would have got the details if the actionForm was in session scope. If I originally put the actionForm into session scope in struts-config.xml file, there are some other aspects which i have to take care and that is problamatic for me.

I have tried to put the actionForm into session in this way:

session.setAttribute("newReservationForm",newFormObj); and I hope the struts tags should be able to find the actionForm , which it is not doing.

I hope you are clear with what I am trying to do.

[ September 02, 2004: Message edited by: Shankar Narayana ]
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415

Once the scope is set in struts-config u cant change as this will be loaded when the server is started....but even if use the trick of setting the bean in that particular scope u should use the tags by compulsorily saying scope="session/request" if u dont give this the way strust looks up is first applictaion/session/request and so conflict may happen .To avoid all this duplicate ur bean and put it in session/req with different name rather than the same ..........still u can use the struts tags
I agree. Here's the link:
subject: Changing Scope dynamically
jQuery in Action, 3rd edition