You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/06/13 19:53:54 UTC

advice- session vs request scope for Action Form

It seems as though the majority of times your ActionForms should use
request scope, but what about situations where you might grab data
from one jsp form and then need to use the information you got from
that page during other parts of your application. Here's the actual
situation...

1) user has to select a "userType" from some select options.
2) once this "userType" is selected I need to use this property in
some DispatchAction methods and as a display on some other pages as
the user traverses the application. (the "userType" can change if he/she
goes back to the original form and selects a new one).

Now the question is where should the "userType" field be stored so I
have access to it in other parts of the user's session? I first
thought it would be best stored as a field in my ActionForm with
session scope so that other pages and Actions could have access to it,
but if reset() is always called regardless of the scope it seems to
imply that the ActionForms shouldn't really be used in Sesion scope?
(Even though the default reset behavior wouldn't reset my field upon
each request unless I provide implementation, it seems to imply that I
should provide the implementation, and definitely as Chuck pointed out
to me, in the case of DynaActionForms, the reset will truly reset the
fields to default values, which means if I use a DynaActionForm and
want it in Session scope I have to override the reset() method and
make sure it doesn't touch the fields I want to keep in the session.
That sort of seems ugly to me.)

Am I better off just sticking the "userType" variable itself into the
session after I get it from the Form? Or maybe just put it into
the DTO (that I eventually convert the ActionForm into anyway) and
then stick that DTO in the session?

Thanks for any comments.

-- 

Rick
mailto:maillist@reumann.net

"Any man, in the right situation, is capable of murder. But not any
man is capable of being a good camper. So, murder and camping are not
as similar as you might think." 
  -Jack Handey


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: advice- session vs request scope for Action Form

Posted by Ted Husted <hu...@apache.org>.
Generally, the reset() on an ActionForm should only be used on
checkboxes or things that really need to be reset. Many of us have been
using it reset things to their defaults, but in practice, there seems to
be no point to that, outside of the checkbox issue. 

So, go ahead and use a session-scope bean if that's what you need. 

If the DynaActionForm reset is getting in your way, then subclass it,
and make it do what ~you~ want. After all, this is still OOP. =:0) We
are ~suppose~ to subclass methods that don't work the way we want them
to. That's the ~beauty~ of OOP. 

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services

Rick Reumann wrote:
> 
> It seems as though the majority of times your ActionForms should use
> request scope, but what about situations where you might grab data
> from one jsp form and then need to use the information you got from
> that page during other parts of your application. Here's the actual
> situation...
> 
> 1) user has to select a "userType" from some select options.
> 2) once this "userType" is selected I need to use this property in
> some DispatchAction methods and as a display on some other pages as
> the user traverses the application. (the "userType" can change if he/she
> goes back to the original form and selects a new one).
> 
> Now the question is where should the "userType" field be stored so I
> have access to it in other parts of the user's session? I first
> thought it would be best stored as a field in my ActionForm with
> session scope so that other pages and Actions could have access to it,
> but if reset() is always called regardless of the scope it seems to
> imply that the ActionForms shouldn't really be used in Sesion scope?
> (Even though the default reset behavior wouldn't reset my field upon
> each request unless I provide implementation, it seems to imply that I
> should provide the implementation, and definitely as Chuck pointed out
> to me, in the case of DynaActionForms, the reset will truly reset the
> fields to default values, which means if I use a DynaActionForm and
> want it in Session scope I have to override the reset() method and
> make sure it doesn't touch the fields I want to keep in the session.
> That sort of seems ugly to me.)
> 
> Am I better off just sticking the "userType" variable itself into the
> session after I get it from the Form? Or maybe just put it into
> the DTO (that I eventually convert the ActionForm into anyway) and
> then stick that DTO in the session?
> 
> Thanks for any comments.
> 
> --
> 
> Rick
> mailto:maillist@reumann.net
> 
> "Any man, in the right situation, is capable of murder. But not any
> man is capable of being a good camper. So, murder and camping are not
> as similar as you might think."
>   -Jack Handey
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>