You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chris Cheshire <ch...@gmail.com> on 2006/02/24 23:31:21 UTC

passing objects from one request to another

I have the following chain of events in an app

ActionA -> PageA -> ActionB -> ActionC

All transitions are forward requests (not redirects) and PageA ->
ActionB is a POST.

In ActionA I have a form bean prepopulated with a collection to
display and choose one of in PageA. ActionB then needs to get this
info back out of the form.

The problem is, since everything is in request scope, once the ActionA
-> PageA forward is completed, the bean is no longer valid. Is there
any way to get the bean to transfer to the next request, or do I need
to use a session bean instead (definitely not ideal as then I have to
put the cleanup for it in numerous places).

Thanks

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Rick Reumann <st...@reumann.net>.
Chris Cheshire wrote the following on 2/24/2006 5:31 PM:
>  
> The problem is, since everything is in request scope, once the ActionA
> -> PageA forward is completed, the bean is no longer valid. Is there
> any way to get the bean to transfer to the next request, or do I need
> to use a session bean instead (definitely not ideal as then I have to
> put the cleanup for it in numerous places).

I'd use the session, but if you don't want to use that then make sure 
you put what you need into hidden variables.

-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/24/06, Jim Reynolds <ji...@gmail.com> wrote:
> I recommend not using session, unless it is completely necessary. I
> have had memory issues, and other problems like garbage colleciton
> when putting information into the session. Basically like one of the
> other responders said, just populate your form, do your validation,
> and pass it along to another action. In the next form, if you just
> want to pass the variables to the next form, just put them into hidden
> fields in that form. Still using the same bean, they will get
> autopopulated, and so on and so on.

Then you type URL of ActionB in the address line, hit Enter and see
how your application blows up.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Bryan LaPlante <br...@xoscript.org>.
my output stream has to be controlled by my action class. It is an ajax
integration for http://www.xoscript.org
where you can invoke methods on a POJO class and in turn that class can
include the output of another action as it's return value.

----- Original Message -----
From: "Rick Reumann" <st...@reumann.net>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Saturday, February 25, 2006 12:11 PM
Subject: Re: passing objects from one request to another


> bryan@xoscript.org wrote:
> > Rick,
> >
> > It sounds like you are having a problem that I solved last week.
>
> Actually, I'm not the one having the problem. I was just replying to the
> initial post, that I'd use the Session for stuff that needs to accessed
> across multiple requests.
>
> > I had a situation where I needed to include the result of other actions
in the
> > middle of my ActionClass so I implement HttpServletRequestWrapper and
> > HttpServletResponseWrapper so that I could provide RequestDispatcher
with a
> > place to store and retrieve variables from the request scope. In my
action
> > class I swapped the real request and response for the wrapped ones and
copied
> > all the request.getParmeters() and so on into a Hashtable in my wrapper
> > classes. When I called dispatch.include(req,res) the new action.do was
able to
> > function as if I forwarded control to the new action class. In order to
> > retrieve the output buffer coming back I created one in my response
wrapper
> > using a String buffer so that I could get at with the toString method.
>
> No offense, but that sounds like a case where trying to be creative just
> made things way more complicated than they need to be. If you need
> something in other Action classes across multiple requests why not just
> stuff some object into the Session instead of going through all these
> hoops? Why in the world would you need to create wrapper classes and
> push the storage of these objects up into the RequestDispatcher? What
> does this gain you versus just storing some object in the Session?
>
> --
> Rick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Rick Reumann <st...@reumann.net>.
bryan@xoscript.org wrote:
> Rick,
> 
> It sounds like you are having a problem that I solved last week.

Actually, I'm not the one having the problem. I was just replying to the 
initial post, that I'd use the Session for stuff that needs to accessed 
across multiple requests.

> I had a situation where I needed to include the result of other actions in the
> middle of my ActionClass so I implement HttpServletRequestWrapper and
> HttpServletResponseWrapper so that I could provide RequestDispatcher with a
> place to store and retrieve variables from the request scope. In my action
> class I swapped the real request and response for the wrapped ones and copied
> all the request.getParmeters() and so on into a Hashtable in my wrapper
> classes. When I called dispatch.include(req,res) the new action.do was able to
> function as if I forwarded control to the new action class. In order to
> retrieve the output buffer coming back I created one in my response wrapper
> using a String buffer so that I could get at with the toString method. 

No offense, but that sounds like a case where trying to be creative just 
made things way more complicated than they need to be. If you need 
something in other Action classes across multiple requests why not just 
stuff some object into the Session instead of going through all these 
hoops? Why in the world would you need to create wrapper classes and 
push the storage of these objects up into the RequestDispatcher? What 
does this gain you versus just storing some object in the Session?

-- 
Rick


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by "bryan@xoscript.org" <br...@xoscript.org>.
Rick,

It sounds like you are having a problem that I solved last week. I did not get
in on the beginning of this conversation so I will give you a rough draft of
what I did and you can ask me for my code if it will help your situation.

I had a situation where I needed to include the result of other actions in the
middle of my ActionClass so I implement HttpServletRequestWrapper and
HttpServletResponseWrapper so that I could provide RequestDispatcher with a
place to store and retrieve variables from the request scope. In my action
class I swapped the real request and response for the wrapped ones and copied
all the request.getParmeters() and so on into a Hashtable in my wrapper
classes. When I called dispatch.include(req,res) the new action.do was able to
function as if I forwarded control to the new action class. In order to
retrieve the output buffer coming back I created one in my response wrapper
using a String buffer so that I could get at with the toString method. 

This is all open source code, so if any of it sounds useful just ask and I
will send it to you.

Bryan LaPlante

---------- Original Message -----------
From: Rick Reumann <st...@reumann.net>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Fri, 24 Feb 2006 21:41:11 -0500
Subject: Re: passing objects from one request to another

> Jim Reynolds wrote:
> > 
> > IMOHO it is best to stay away from session information unless it is
> > something that is necessary for the full site.
> 
> imo, the Session is better than using hidden variables. People freak out 
> over using the Session like it's something taboo.  If it's a trade off 
> between complicating my app or using the Session - I'd vote for using 
> the Session every time.
> 
> -- 
> Rick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
------- End of Original Message -------

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Rick Reumann <st...@reumann.net>.
Jim Reynolds wrote:
> 
> IMOHO it is best to stay away from session information unless it is
> something that is necessary for the full site.

imo, the Session is better than using hidden variables. People freak out 
over using the Session like it's something taboo.  If it's a trade off 
between complicating my app or using the Session - I'd vote for using 
the Session every time.

-- 
Rick



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Jim Reynolds <ji...@gmail.com>.
I recommend not using session, unless it is completely necessary. I
have had memory issues, and other problems like garbage colleciton
when putting information into the session. Basically like one of the
other responders said, just populate your form, do your validation,
and pass it along to another action. In the next form, if you just
want to pass the variables to the next form, just put them into hidden
fields in that form. Still using the same bean, they will get
autopopulated, and so on and so on.

IMOHO it is best to stay away from session information unless it is
something that is necessary for the full site.



On 2/24/06, Chris Cheshire <ch...@gmail.com> wrote:
> The problem is there is other information in the form bean that is not
> in the page, therefore it is not getting initialised properly.
>
> I am going with the hidden variable approach as suggested.
>
> On 2/24/06, Michael Jouravlev <jm...@gmail.com> wrote:
> > On 2/24/06, Chris Cheshire <ch...@gmail.com> wrote:
> > > I have the following chain of events in an app
> > >
> > > ActionA -> PageA -> ActionB -> ActionC
> > >
> > > All transitions are forward requests (not redirects) and PageA ->
> > > ActionB is a POST.
> > >
> > > In ActionA I have a form bean prepopulated with a collection to
> > > display and choose one of in PageA. ActionB then needs to get this
> > > info back out of the form.
> > >
> > > The problem is, since everything is in request scope, once the ActionA
> > > -> PageA forward is completed, the bean is no longer valid. Is there
> > > any way to get the bean to transfer to the next request, or do I need
> > > to use a session bean instead (definitely not ideal as then I have to
> > > put the cleanup for it in numerous places).
> >
> > Since you submit pageA to actionB, the form associated with actionB
> > will be filled out with data from pageA. I don't see what the problem
> > is. Yes, ActionForm will be created again.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Chris Cheshire <ch...@gmail.com>.
The problem is there is other information in the form bean that is not
in the page, therefore it is not getting initialised properly.

I am going with the hidden variable approach as suggested.

On 2/24/06, Michael Jouravlev <jm...@gmail.com> wrote:
> On 2/24/06, Chris Cheshire <ch...@gmail.com> wrote:
> > I have the following chain of events in an app
> >
> > ActionA -> PageA -> ActionB -> ActionC
> >
> > All transitions are forward requests (not redirects) and PageA ->
> > ActionB is a POST.
> >
> > In ActionA I have a form bean prepopulated with a collection to
> > display and choose one of in PageA. ActionB then needs to get this
> > info back out of the form.
> >
> > The problem is, since everything is in request scope, once the ActionA
> > -> PageA forward is completed, the bean is no longer valid. Is there
> > any way to get the bean to transfer to the next request, or do I need
> > to use a session bean instead (definitely not ideal as then I have to
> > put the cleanup for it in numerous places).
>
> Since you submit pageA to actionB, the form associated with actionB
> will be filled out with data from pageA. I don't see what the problem
> is. Yes, ActionForm will be created again.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing objects from one request to another

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/24/06, Chris Cheshire <ch...@gmail.com> wrote:
> I have the following chain of events in an app
>
> ActionA -> PageA -> ActionB -> ActionC
>
> All transitions are forward requests (not redirects) and PageA ->
> ActionB is a POST.
>
> In ActionA I have a form bean prepopulated with a collection to
> display and choose one of in PageA. ActionB then needs to get this
> info back out of the form.
>
> The problem is, since everything is in request scope, once the ActionA
> -> PageA forward is completed, the bean is no longer valid. Is there
> any way to get the bean to transfer to the next request, or do I need
> to use a session bean instead (definitely not ideal as then I have to
> put the cleanup for it in numerous places).

Since you submit pageA to actionB, the form associated with actionB
will be filled out with data from pageA. I don't see what the problem
is. Yes, ActionForm will be created again.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org