You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Graham Lounder <lo...@caris.com> on 2002/05/08 14:10:47 UTC
Session and Forms
Hello all,
Maybe this is an common knownledge, but I'll ask it anyways. Let say I have user details object in the session. I also have a struts user form to modify these details. When the user form is created, do I load the form object from the session object? Is there a was to keep the user form from being disregarded when browsing other sections of a web site? I tried putting the form in the session but this did not work (maybe its getting reset somewhere, I'm not sure).
Any Ideas,
Graham
Re: Session and Forms
Posted by Graham Lounder <lo...@caris.com>.
Thanks Craig, its the solution I was looking for. I didn't think you could
keep a Form Bean in the session but I wasn't sure. It is better to make a
distinction between the model and the forms.
Thanks again,
Graham
----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, May 08, 2002 12:26 PM
Subject: Re: Session and Forms
>
>
> On Wed, 8 May 2002, Graham Lounder wrote:
>
> > Date: Wed, 8 May 2002 09:10:47 -0300
> > From: Graham Lounder <lo...@caris.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: Session and Forms
> >
> > Hello all,
> >
> > Maybe this is an common knownledge, but I'll ask it anyways. Let say I
> > have user details object in the session. I also have a struts user form
> > to modify these details. When the user form is created, do I load the
> > form object from the session object? Is there a was to keep the user
> > form from being disregarded when browsing other sections of a web site?
> > I tried putting the form in the session but this did not work (maybe its
> > getting reset somewhere, I'm not sure).
> >
>
> The Struts example app has almost exactly this scenario, and it's worth
> looking at how the problem is solved there.
>
> Once you log on, the User record (corresponding to your user details) is
> in the session. But the application thinks of that as "model data", not
> as a form bean. It's used to provide read-only information in other parts
> of the system.
>
> When you want to edit your own user info -- the kind of thing that would
> be common on a portal site, for example -- you will note that the
> hyperlink goes to an action (/editRegistration.do) which:
> * Creates a UserForm bean
> * Populates the form bean from the user details
> * Forewards to the "/registration.jsp" page for editing.
>
> When the form is actually submitted, it goes to a different action
> (/saveRegistration.do) that, if the transaction passes all the validation
> tests, and it was not cancelled, actually updates the "database". In this
> case, that's actually the same object as is stored in the session. For
> most people, this would be a database update.
>
> This pattern seems to work very well, whether the model data is already in
> your session or whether you need to load it from a database.
>
> > Any Ideas,
> > Graham
> >
>
> Craig McClanahan
>
>
>
> --
> 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>
Re: Session and Forms
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Wed, 8 May 2002, Graham Lounder wrote:
> Date: Wed, 8 May 2002 09:10:47 -0300
> From: Graham Lounder <lo...@caris.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Session and Forms
>
> Hello all,
>
> Maybe this is an common knownledge, but I'll ask it anyways. Let say I
> have user details object in the session. I also have a struts user form
> to modify these details. When the user form is created, do I load the
> form object from the session object? Is there a was to keep the user
> form from being disregarded when browsing other sections of a web site?
> I tried putting the form in the session but this did not work (maybe its
> getting reset somewhere, I'm not sure).
>
The Struts example app has almost exactly this scenario, and it's worth
looking at how the problem is solved there.
Once you log on, the User record (corresponding to your user details) is
in the session. But the application thinks of that as "model data", not
as a form bean. It's used to provide read-only information in other parts
of the system.
When you want to edit your own user info -- the kind of thing that would
be common on a portal site, for example -- you will note that the
hyperlink goes to an action (/editRegistration.do) which:
* Creates a UserForm bean
* Populates the form bean from the user details
* Forewards to the "/registration.jsp" page for editing.
When the form is actually submitted, it goes to a different action
(/saveRegistration.do) that, if the transaction passes all the validation
tests, and it was not cancelled, actually updates the "database". In this
case, that's actually the same object as is stored in the session. For
most people, this would be a database update.
This pattern seems to work very well, whether the model data is already in
your session or whether you need to load it from a database.
> Any Ideas,
> Graham
>
Craig McClanahan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>