This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Changing Scope dynamically" Watch "Changing Scope dynamically" New topic
Author

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


Thanks,
Shankar


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

Joined: May 26, 2003
Posts: 30076
    
149

Shankar,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.

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

Joined: Sep 21, 2003
Posts: 415
Hi

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: http://aspose.com/file-tools
 
subject: Changing Scope dynamically
 
Similar Threads
View cannot be restored exception
How to set and get attributes in servlet.
EL param and page scope vars
Need Help!
Related to Session and Request objects