You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2003/09/09 04:33:10 UTC

How to reference multiple Struts form beans from one VelocityLayoutServlet set of page fragments?

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

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.

Reference to how it could be done in pure jsp:

	http://www.mail-archive.com/struts-user@jakarta.apache.org/msg22976.html

Reference to how multiple forms may not work with Velocity:

	http://www.mail-archive.com/velocity-dev@jakarta.apache.org/msg06945.html

Contrary reference that it might be possible to reference "multiple forms" 
with $form in Velocity:

	http://www.mail-archive.com/velocity-dev@jakarta.apache.org/msg05261.html


Probably unimportant details:

I'm using Struts 1.1, Tomcat 4.1.27, the Validator, and the 
VelocityLayoutServlet from Velocity-tools-1.0.  I've got my layout broken 
out into the generic standard:

layout
	header
	menu
	body
	footer

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.

Thanks!

-Mike


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

Posted by Nathan Bubna <na...@esha.com>.
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