What would have been ideal would have been to allow Struts configuration to tie more than one ActionForm to an Action. Then page-centric and action-centric thinkers would have had common ground. As things stand, you can avoid much of the sophistication in what Hubert is suggesting by having an ActionForm that services two or more JSP/html forms. This is actually advisable or good for other reasons too. I am not suggesting that Hubert is wrong. He is an ace programmer and architect. I am just saying that this is a pretty complicated way to go for a fairly simple problem.
On Fri, 11 Mar 2005 10:15:53 -0700, Schuster Joel M Contr ESC/NDC <[EMAIL PROTECTED]> wrote: > Thanks... I'll keep playing around using your suggestions. > > > -----Original Message----- > From: Hubert Rabago [mailto:[EMAIL PROTECTED] > 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 > <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] > > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]