struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Reumann <maill...@reumann.net>
Subject Re: one more prepopulate question
Date Sat, 01 Mar 2003 16:18:11 GMT
On Sat, Mar 01,'03 (02:23 AM GMT-0600), Dan wrote: 
 ore veteraned user.
> 
> I just see this whole multiple-form prepopulate question cropping up
> time and again on this list if we don't have something in the FAQ
> about it.

Coupled with the tidbits someone posted from Craig's snipet what
would be wrong with this approach: 

You have an Action class that you want to use to prepopulate three
Action Forms and then forward to a JSP page and set up three separate
forms. So you might have a mapping...

<action path="/setupMultipleForms"
        type="foo.bar.SetUpFormsAction"
        name="form1"
        scope="request"
        validate="false"
        >
        <forward
                name="continue"
                path="/severalFormsOnAPage.jsp"/>
</action>

So now in the SetUpFormsAction you can easily put Form1 into scope by:
 
Form1 form1 = (Form1)form;
form1.setFoo("hello");
request.setAttribute(mapping.getAttribute(), form1 );

But now for another ActionForm (Form2) to put into scope you could do:

But probably better would be to use what I think I gleamed Craig
mention: (assuming form2 is tied to /foo in mapping):

ApplicationConfig appConfig = (ApplicationConfig)
		request.getAttribute(Globals.APPLICATION_KEY);
ActionConfig actionConfig = appConfig.findActionConfig("/foo");
String name = actionConfig.getName(); // Form bean name

Form2 form2 = new Form2();
form2.setFooBar("BLA");
request.setAttribute( name, form2 );

for form3...

actionConfig = appConfig.findActionConfig("/fooForm3Action");
name = actionConfig.getName(); // Form bean name
Form3 form3 = new Form3();
form3.setBoo("hello world");
request.setAttribute( name, form3 );



Then on the JSP page you just use the <html:form> tags as you normally
would if there was just one form on the page.

-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message