You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hohlen, John" <JH...@erac.com> on 2002/09/30 15:22:29 UTC

SURVEY: Proper Way To Pre-populate ActionForms

I was wondering what the overall philosophy is in the Struts Users community
in regards to pre-populating action forms?  I sent a message out late last
week asking for help on how to manually instantiate and pre-populate an
action form (prior to forwarding to a JS) in Struts 1.1.  That's when I
realized this may be considered bad practice.  Here are some comments I
received:

Eddie Bush:
"No, no.  Actions/Forms have a contract -- the form 'will' be created. 
You should not take this upon yourself.  What you need to do is pre-face 
the page with a 'populate' action. Expect it to be there"

James Turner:
I can still point to cases where you need to manually pre-populate. 
For example, if you have multiple forms on a single JSP page, you either 
need to pre-populate the forms manually, or you'd have to daisy-chain a 
bunch of actions together, each one of which was responsible for 
pre-populating a single form. This seems clumsy to me. Maybe what we need 
is an authoritative way (i.e., an API) to instantiate DynaForms.

What are others doing here?  BTW, if manually pre-populating an action form
is acceptable, does it make sense to create a method in the "RequestUtils"
package making this
easy to do for a DynaForm (Struts 1.1).  For example (code provided by James
Turner): 

ApplicationConfig appConfig =
         (ApplicationConfig)request.getAttribute(Action.APPLICATION_KEY);
FormBeanConfig formBeanConfig =
          appConfig.findFormBeanConfig("myDynaActionForm");
String beanType = formBeanConfig.getType();
DynaActionForm bean;
DynaActionFormClass formClass =
              DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
return (DynaActionForm) formClass.newInstance();

Thanks! JOHN


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


Re: SURVEY: Proper Way To Pre-populate ActionForms

Posted by "Craig R. McClanahan" <cr...@apache.org>.
The struts-example app (which uses a separate action for the setup) is the
method that I recommend for manually setting up an ActionForm instance,
plus any other beans that need to be looked up and placed in request
scope.  To remind you of the relationships, the actions and the JSP page
are named similarly:

* editRegistration.do -- Set up the "registration.jsp" form bean

* registration.do -- The input page for registration information

* saveRegistration.do -- Save the new or updated registration
  information to the database

It's fine to rely on the auto-creation of the form bean if you don't need
to look up any database information (i.e. you're going to be doing a
"create" type transaction), where you just make your reset() method set up
all the defaults.  However, if you're going to do an "edit" transaction
against existing data from the database, I prefer to look that up in a
setup action rather than make the reset() method have to go to the
database itself.

Craig McClanahan


On Mon, 30 Sep 2002, Hohlen, John wrote:

> Date: Mon, 30 Sep 2002 08:22:29 -0500
> From: "Hohlen, John" <JH...@erac.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "Struts-Help (E-mail)" <st...@jakarta.apache.org>
> Cc: "'struts-dev@jakarta.apache.org'" <st...@jakarta.apache.org>
> Subject: SURVEY: Proper Way To Pre-populate ActionForms
>
> I was wondering what the overall philosophy is in the Struts Users community
> in regards to pre-populating action forms?  I sent a message out late last
> week asking for help on how to manually instantiate and pre-populate an
> action form (prior to forwarding to a JS) in Struts 1.1.  That's when I
> realized this may be considered bad practice.  Here are some comments I
> received:
>
> Eddie Bush:
> "No, no.  Actions/Forms have a contract -- the form 'will' be created.
> You should not take this upon yourself.  What you need to do is pre-face
> the page with a 'populate' action. Expect it to be there"
>
> James Turner:
> I can still point to cases where you need to manually pre-populate.
> For example, if you have multiple forms on a single JSP page, you either
> need to pre-populate the forms manually, or you'd have to daisy-chain a
> bunch of actions together, each one of which was responsible for
> pre-populating a single form. This seems clumsy to me. Maybe what we need
> is an authoritative way (i.e., an API) to instantiate DynaForms.
>
> What are others doing here?  BTW, if manually pre-populating an action form
> is acceptable, does it make sense to create a method in the "RequestUtils"
> package making this
> easy to do for a DynaForm (Struts 1.1).  For example (code provided by James
> Turner):
>
> ApplicationConfig appConfig =
>          (ApplicationConfig)request.getAttribute(Action.APPLICATION_KEY);
> FormBeanConfig formBeanConfig =
>           appConfig.findFormBeanConfig("myDynaActionForm");
> String beanType = formBeanConfig.getType();
> DynaActionForm bean;
> DynaActionFormClass formClass =
>               DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
> return (DynaActionForm) formClass.newInstance();
>
> Thanks! JOHN
>
>
> --
> 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: SURVEY: Proper Way To Pre-populate ActionForms

Posted by "Craig R. McClanahan" <cr...@apache.org>.
The struts-example app (which uses a separate action for the setup) is the
method that I recommend for manually setting up an ActionForm instance,
plus any other beans that need to be looked up and placed in request
scope.  To remind you of the relationships, the actions and the JSP page
are named similarly:

* editRegistration.do -- Set up the "registration.jsp" form bean

* registration.do -- The input page for registration information

* saveRegistration.do -- Save the new or updated registration
  information to the database

It's fine to rely on the auto-creation of the form bean if you don't need
to look up any database information (i.e. you're going to be doing a
"create" type transaction), where you just make your reset() method set up
all the defaults.  However, if you're going to do an "edit" transaction
against existing data from the database, I prefer to look that up in a
setup action rather than make the reset() method have to go to the
database itself.

Craig McClanahan


On Mon, 30 Sep 2002, Hohlen, John wrote:

> Date: Mon, 30 Sep 2002 08:22:29 -0500
> From: "Hohlen, John" <JH...@erac.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "Struts-Help (E-mail)" <st...@jakarta.apache.org>
> Cc: "'struts-dev@jakarta.apache.org'" <st...@jakarta.apache.org>
> Subject: SURVEY: Proper Way To Pre-populate ActionForms
>
> I was wondering what the overall philosophy is in the Struts Users community
> in regards to pre-populating action forms?  I sent a message out late last
> week asking for help on how to manually instantiate and pre-populate an
> action form (prior to forwarding to a JS) in Struts 1.1.  That's when I
> realized this may be considered bad practice.  Here are some comments I
> received:
>
> Eddie Bush:
> "No, no.  Actions/Forms have a contract -- the form 'will' be created.
> You should not take this upon yourself.  What you need to do is pre-face
> the page with a 'populate' action. Expect it to be there"
>
> James Turner:
> I can still point to cases where you need to manually pre-populate.
> For example, if you have multiple forms on a single JSP page, you either
> need to pre-populate the forms manually, or you'd have to daisy-chain a
> bunch of actions together, each one of which was responsible for
> pre-populating a single form. This seems clumsy to me. Maybe what we need
> is an authoritative way (i.e., an API) to instantiate DynaForms.
>
> What are others doing here?  BTW, if manually pre-populating an action form
> is acceptable, does it make sense to create a method in the "RequestUtils"
> package making this
> easy to do for a DynaForm (Struts 1.1).  For example (code provided by James
> Turner):
>
> ApplicationConfig appConfig =
>          (ApplicationConfig)request.getAttribute(Action.APPLICATION_KEY);
> FormBeanConfig formBeanConfig =
>           appConfig.findFormBeanConfig("myDynaActionForm");
> String beanType = formBeanConfig.getType();
> DynaActionForm bean;
> DynaActionFormClass formClass =
>               DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
> return (DynaActionForm) formClass.newInstance();
>
> Thanks! JOHN
>
>
> --
> 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>