You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Paransky <al...@individualnetwork.com> on 2002/03/18 22:49:43 UTC

How to properly map actions for form edit and save functions?

I have a Form and two actions FormLoad.do and FormSave.do.  Both of these
actions have scope set to "request".

The FormLoad.do initializes the form with data by configuring various
collections (later used for options on the view), it is set to
validate="false".

The FormSave.do attempts to save the data entered by the user into the
database.  It is set to validate="true".

At this point, should the input parameter of the FormSave.do action
reference the .jsp page (view) or the FormLoad.do action?  If I reference
the .jsp page directly, the data needed by .jsp is not in the form for
display (since the new form bean was never loaded for a new request).  On
the other hand, if I reference FormLoad.do, the data is loaded, but would
user's input be saved in case of an error?  Should I change the scope of the
FormLoad.do and FormSave.do to session and have the input point to .jsp
page?  If so, when should I remove (cleanup) the bean from the session?  At
the end of the successful FormSave.do?  What if the user never presses the
submit button and just leaves the form?  Should the FormLoad.do, then also
try to remove any existing form beans from the session?

Do you put your form beans in the session or request?

I am looking for a "clean" pattern that I can use across all my Forms.
Currently, there is no set standard that I use for this type of interaction.

Thanks.

-------------
-AP_
See my profile at
http://www.myprofiles.com/member/view.do?profileId=128



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


Re: How to properly map actions for form edit and save functions?

Posted by Ted Husted <hu...@apache.org>.
If the LoadForm Action class is not clearing the user-supplied
properties itself, then the user-supplied input should be there. 

Typically, an Action like this will just add collections for drop-down
elements and so forth, and trust that the ActionForm bean's default
properties are fine the way they are. 

If you are setting the defaults in the Action for properties that user's
also supply, then I would start out by having the fields initialize to
null in the ActionForm class, and then have the setter ignore new input
when the field is not null. This makes them "write-once" fields, which
is generally all you ever want in a request-scope bean anyway. 

-- 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


Alex Paransky wrote:
> 
> Ted,
> 
> Assuming I use scope="request", and have to actions LoadForm.do and
> SaveForm.do.  If then, I configure the input of SaveForm.do to be
> LoadForm.do, wouldn't user's input be erased if LoadForm.do gets called in
> case of an error?  In my development, a Form contains all the components
> necessary to render the .jsp view.  In other words, it contains the
> necessary information to display all the options, not just the selected
> option.  The LoadForm.do loads the form "completely".  So if it's used on
> the input="" parameter, the user's input might get lost in case of an error.
> 
> Am I missing something?  I am just looking for a pattern that would allow me
> to write less code and repeat of all types for Form/Action interactions.
> 
> -AP_
> http://www.alexparansky.com
> Java/J2EE Architect/Consultant
> http://www.myprofiles.com/member/view.do?profileId=127
> 
> -----Original Message-----
> From: Ted Husted [mailto:husted@apache.org]
> Sent: Tuesday, March 19, 2002 8:19 AM
> To: Struts Users Mailing List
> Subject: Re: How to properly map actions for form edit and save
> functions?
> 
> The input property can refer directly to the page, if it doesn't need
> any "helper" beans in the request to populate drop-down boxes and such.
> 
> When the form is submitted, the elements of the form are made part of
> the request, and Struts sucks these into an ActionForm for you. But if
> the FormLoad is providing objects or data that do not come from the HTMl
> form, you would have to go back through an Action to create them again.
> 
> The cleanest thing is to link input to an action-mapping rather than a
> page.
> 
> -- 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
> 
> Alex Paransky wrote:
> >
> > I have a Form and two actions FormLoad.do and FormSave.do.  Both of these
> > actions have scope set to "request".
> >
> > The FormLoad.do initializes the form with data by configuring various
> > collections (later used for options on the view), it is set to
> > validate="false".
> >
> > The FormSave.do attempts to save the data entered by the user into the
> > database.  It is set to validate="true".
> >
> > At this point, should the input parameter of the FormSave.do action
> > reference the .jsp page (view) or the FormLoad.do action?  If I reference
> > the .jsp page directly, the data needed by .jsp is not in the form for
> > display (since the new form bean was never loaded for a new request).  On
> > the other hand, if I reference FormLoad.do, the data is loaded, but would
> > user's input be saved in case of an error?  Should I change the scope of
> the
> > FormLoad.do and FormSave.do to session and have the input point to .jsp
> > page?  If so, when should I remove (cleanup) the bean from the session?
> At
> > the end of the successful FormSave.do?  What if the user never presses the
> > submit button and just leaves the form?  Should the FormLoad.do, then also
> > try to remove any existing form beans from the session?
> >
> > Do you put your form beans in the session or request?
> >
> > I am looking for a "clean" pattern that I can use across all my Forms.
> > Currently, there is no set standard that I use for this type of
> interaction.
> >
> > Thanks.
> >
> > -------------
> > -AP_
> > See my profile at
> > http://www.myprofiles.com/member/view.do?profileId=128
> >
> > --
> > 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>
> 
> --
> 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: How to properly map actions for form edit and save functions?

Posted by Alex Paransky <ap...@standardset.com>.
Ted,

Assuming I use scope="request", and have to actions LoadForm.do and
SaveForm.do.  If then, I configure the input of SaveForm.do to be
LoadForm.do, wouldn't user's input be erased if LoadForm.do gets called in
case of an error?  In my development, a Form contains all the components
necessary to render the .jsp view.  In other words, it contains the
necessary information to display all the options, not just the selected
option.  The LoadForm.do loads the form "completely".  So if it's used on
the input="" parameter, the user's input might get lost in case of an error.

Am I missing something?  I am just looking for a pattern that would allow me
to write less code and repeat of all types for Form/Action interactions.

-AP_
http://www.alexparansky.com
Java/J2EE Architect/Consultant
http://www.myprofiles.com/member/view.do?profileId=127

-----Original Message-----
From: Ted Husted [mailto:husted@apache.org]
Sent: Tuesday, March 19, 2002 8:19 AM
To: Struts Users Mailing List
Subject: Re: How to properly map actions for form edit and save
functions?


The input property can refer directly to the page, if it doesn't need
any "helper" beans in the request to populate drop-down boxes and such.

When the form is submitted, the elements of the form are made part of
the request, and Struts sucks these into an ActionForm for you. But if
the FormLoad is providing objects or data that do not come from the HTMl
form, you would have to go back through an Action to create them again.

The cleanest thing is to link input to an action-mapping rather than a
page.

-- 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


Alex Paransky wrote:
>
> I have a Form and two actions FormLoad.do and FormSave.do.  Both of these
> actions have scope set to "request".
>
> The FormLoad.do initializes the form with data by configuring various
> collections (later used for options on the view), it is set to
> validate="false".
>
> The FormSave.do attempts to save the data entered by the user into the
> database.  It is set to validate="true".
>
> At this point, should the input parameter of the FormSave.do action
> reference the .jsp page (view) or the FormLoad.do action?  If I reference
> the .jsp page directly, the data needed by .jsp is not in the form for
> display (since the new form bean was never loaded for a new request).  On
> the other hand, if I reference FormLoad.do, the data is loaded, but would
> user's input be saved in case of an error?  Should I change the scope of
the
> FormLoad.do and FormSave.do to session and have the input point to .jsp
> page?  If so, when should I remove (cleanup) the bean from the session?
At
> the end of the successful FormSave.do?  What if the user never presses the
> submit button and just leaves the form?  Should the FormLoad.do, then also
> try to remove any existing form beans from the session?
>
> Do you put your form beans in the session or request?
>
> I am looking for a "clean" pattern that I can use across all my Forms.
> Currently, there is no set standard that I use for this type of
interaction.
>
> Thanks.
>
> -------------
> -AP_
> See my profile at
> http://www.myprofiles.com/member/view.do?profileId=128
>
> --
> 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>



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


Re: How to properly map actions for form edit and save functions?

Posted by Ted Husted <hu...@apache.org>.
The input property can refer directly to the page, if it doesn't need
any "helper" beans in the request to populate drop-down boxes and such. 

When the form is submitted, the elements of the form are made part of
the request, and Struts sucks these into an ActionForm for you. But if
the FormLoad is providing objects or data that do not come from the HTMl
form, you would have to go back through an Action to create them again. 

The cleanest thing is to link input to an action-mapping rather than a
page. 

-- 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


Alex Paransky wrote:
> 
> I have a Form and two actions FormLoad.do and FormSave.do.  Both of these
> actions have scope set to "request".
> 
> The FormLoad.do initializes the form with data by configuring various
> collections (later used for options on the view), it is set to
> validate="false".
> 
> The FormSave.do attempts to save the data entered by the user into the
> database.  It is set to validate="true".
> 
> At this point, should the input parameter of the FormSave.do action
> reference the .jsp page (view) or the FormLoad.do action?  If I reference
> the .jsp page directly, the data needed by .jsp is not in the form for
> display (since the new form bean was never loaded for a new request).  On
> the other hand, if I reference FormLoad.do, the data is loaded, but would
> user's input be saved in case of an error?  Should I change the scope of the
> FormLoad.do and FormSave.do to session and have the input point to .jsp
> page?  If so, when should I remove (cleanup) the bean from the session?  At
> the end of the successful FormSave.do?  What if the user never presses the
> submit button and just leaves the form?  Should the FormLoad.do, then also
> try to remove any existing form beans from the session?
> 
> Do you put your form beans in the session or request?
> 
> I am looking for a "clean" pattern that I can use across all my Forms.
> Currently, there is no set standard that I use for this type of interaction.
> 
> Thanks.
> 
> -------------
> -AP_
> See my profile at
> http://www.myprofiles.com/member/view.do?profileId=128
> 
> --
> 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>