You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Nathan Bubna <na...@esha.com> on 2003/09/09 06:04:02 UTC

Re: How to reference multiple Struts form beans from oneVelocityLayoutServlet set of page fragments?

gosh that's a long subject line!

Mike Kienenberger said:
> I posted this question to the Struts mailing list last week and got no
> answers other than using pure jsp or switching to Tiles (which is what I
> just switched from before Velocity).

FYI:  velocity-tools now has a working TilesTool that will be included in our
next release (1.1).  :)

> I need to have two forms displayed on the same combined Velocity template
> page.  One is in a "menu" fragment and the other is in my "content body"
> fragment.  I can receive a reference to one form bean via the ActionMapping.
>  I've been unable to determine how to gain a reference to the second form
> bean.
...

the key here is to remember that forms are stored in the request (or session
if they're session-scoped) under their own names (as defined in your
struts-config), and all request/session/application attributes are
automatically exposed to your templates.  this means that you just reference
your multiple forms by their names instead of through the FormTool.  the
FormTool's getBean() method is really just there for the convenience of not
having to remember the name of the form associated with the current action
mapping.

basically, instead of using $form.bean.someField  do  $MyFooForm.someField

> I've got a form that is generally visible in the menu section.  I have
> arbitrary forms that can appear in the body section, and these I plan to
> pass by the action mapping.  I'm using
> org.apache.struts.validator.DynaValidatorForm for all Form Beans.

sounds fine.  if there's something i've missed or you have other questions,
just ask!

Nathan Bubna
nathan@esha.com