struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schuster Joel M Contr ESC/NDC <Joel.Schus...@cisf.af.mil>
Subject RE: Correct Prepopulate Method
Date Fri, 11 Mar 2005 17:15:53 GMT
Thanks... I'll keep playing around using your suggestions.


-----Original Message-----
From: Hubert Rabago [mailto:hrabago@gmail.com] 
Sent: Friday, March 11, 2005 10:13 AM
To: Struts Users Mailing List
Subject: Re: Correct Prepopulate Method

On Fri, 11 Mar 2005 09:50:59 -0700, Schuster Joel M Contr ESC/NDC
<Joel.Schuster@cisf.af.mil> wrote:
> I'm not sure I understand the need for the moduleConfig and such for
> creating the DynaActionForm.

The FormBeanConfig object provides access to the createActionForm()
method.  That's the object you actually need.  You can get to that
through the ModuleConfig for the current module.

> 
> If we've specified the name="myForm" in the action config then shouldn't
the
> form coming into the execute be and empty version of my form? Thus
allowing:
> 
>      execute( ActionMapping mapping, ActionForm form ... {
>             DynaActionForm myForm = (DynaActionForm) form;
>      }
> 
> (As a matter of fact I know this works :))
> 

This is true when you're in the action to which the form was
submitted.  In the example I gave, this would be the /submitForm
action.  In a setup action, this mapping may not be available or may
be referring to a different form altogether.

> Also, using
> 
> request.getSession().setAttribute("myForm", myForm);
> 
> is exactly the issue. Although it then allows the follow up jsp to gain
> access to the formbean during form(html) creation it doesn't determine how
> then to remove the form from the session except by explicit removal in the
> final update/submit action unless you config the submit as request scope
> only. But that doesn't actually remove the formbean from the session scope
> that we added it into... it just copies it into the request scope too.
> 
> --- so back to sqare one. :P

You can specify which scope you want the form bean to be in (read the
bottom of my prev email).  Struts uses session scope by default, which
is why that's what I mentioned first.  You can choose to use request
scope.

hth,
Hubert

> 
> 
> -----Original Message-----
> From: Hubert Rabago [mailto:hrabago@gmail.com]
> Sent: Friday, March 11, 2005 9:36 AM
> To: Struts Users Mailing List
> Subject: Re: Correct Prepopulate Method
> 
> You would usually do prepopulation in a setup form.  Which scope you
> place the form in depends on how you configure the action that the
> form will be submitted to.  For example, if you have "/showPage.do"
> and "/submitForm.do", where submitForm is configured as:
> 
> <action path="/submitForm" name="myForm" ...>....</action>
> 
> Then in the action for showPage, you'd:
> 
>     ModuleConfig moduleConfig =
> ModuleUtils.getInstance().getModuleConfig(request);
>     FormBeanConfig formBeanConfig =
> moduleConfig.findFormBeanConfig("myForm");
>     DynaActionForm myForm = (DynaActionForm)
> formBeanConfig.createActionForm(getServlet());
> 
>     myForm.set("propName",propValue);
>     request.getSession().setAttribute("myForm", myForm);
> 
> If you want to use request scope, change /submitForm to:
> <action path="/submitForm" name="myForm" scope="request"...>....</action>
> 
> then in showPage:
>     request.setAttribute("myForm", myForm);
> 
> Hubert
>

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


Mime
View raw message