Hue Holleran wrote:
Ted - what's the chance of posting your views (or pointing us to a link) on
how you're using Velocity with Struts. I did have another look at Velocity
after your presentation but I still don't think I can do without tiles -
even with the promise of 'cross platform' Velocity.NET/NVelocity it doesn't
do it for me?

I should probably do a how-to, but here's a clip from a "Tiles Support" thread on the Velocity User list:


=====

Mark de Reeper wrote:
#parse("/WEB-INF/templates/vm/htmlheader.vm")
<table width="100%" border="0">
    <tr>
        <td>#if($header)#parse($header)#end</td>
    </tr>
    <tr>
        <td>#if($body)#parse($body)#end</td>
    </tr>
    <tr>
        <td>#if($footer)#parse($footer)#end</td>
    </tr>
</table>
#parse("/WEB-INF/templates/vm/htmlfooter.vm")

Then define a template to set the layout and the various bits, this is what is loaded as the main template to parse:

#set ($body = "/WEB-INF/templates/vm/templatebody.vm")
#set ($footer = "/WEB-INF/templates/vm/templatefooter.vm")
#set ($header = "/WEB-INF/templates/vm/templateheader.vm")
#parse("/WEB-INF/templates/layouts/layoutHBF.vm")

Ted Husted wrote:
This is just how the original Struts Template library worked. (Great minds and all that.) You defined a second file to administer the template. This works well enough but it tends to generate a lot of "meta-templates" that are just used to call other templates.


As Slavik pointed out, Tiles extended the template library so that you could express the "meta-templates" in XML. Instead of forwarding to the "glockenspiel.vm" template, you can foward to make a reference to say "/vm/Glockenspiel" and Struts will automatically look for a vmGlockenspiel element, do whatever sets you need, and the forward to the layout.

A very neat aspect of Tiles, that we need to adopt for the other Struts configurations, is that one element can extend another. So if you just needed to replace the title on a page, you can extend one element and just "override" that one set. This makes a *huge* difference in maintenance when you pass the thirty page mark.

Until one of us gets around to writing a Tiles tool, I've prototyped what you can do in the Struts config. I've a ViewAction that does the setting. You create the variables to set as Struts ActionForwards and pass their names to ViewAction as ActionMapping parameter. So I have something like this to describe a page:

<action path="/vm/main/permit/View"
 type="us_ok_deq_wqdata.http.ViewAction"
 validate="false"
 name="permit_select_id"
 parameter="vmTitle,vmChoice,vmMenu,vmBody,vmAction,vmButtonBar">
   <forward name="vmTitle" path="Permit Detail" />
   <forward name="vmChoice" path="View" />
   <forward name="vmMenu" path="/cpu/menu/main.vm" />
   <forward name="vmBody" path="/cpu/permit/view.vm" />
   <forward name="vmAction" redirect="false" path="/Main" />
   <forward name="vmButtonBar" path="/cpu/permit/viewMain.vm" />
</action>

To render the same "page" but with a different button bar, I'd just change that forward to include some other template instead.

Besides URI's for parse statements, you can also pass any variable you need to create. For example, "vmChoice" tells the menu which item we are on, so it can dim that one (and leave the rest linked).

While we can't extend struts-config elements (yet), the ActionForwards do have a local and global scope. So you can do things like create a global default forward and let that pass through when it doesn't need to be changed. This is done for the Layout. There's a default "vmLayout" forward which can be overridden by an element if you need to use a different layout.

This works fine inside of Struts and will work even better when we get the Struts config to support extended elements like the Tiles config. But, it seems to me that it's something that could also be done outside of Struts and made available to anyone using Velocity.

For programmers, this sort of thing makes the templates feel object-orientated. You can define a base element and then extend it to say what changes. For designers, they can use Velocity templates seem more like fill-in-the-blank Dreamweaver templates. A GUI, like Struts Console, can even save you from mucking about with XML.

-Ted.

=====


For more see,
< http://www.mail-archive.com/[EMAIL PROTECTED]/msg09304.html >


There's a copy of my ViewAction at
< http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/wqdata/src/java/shared/org_apache_struts_scaffold/ViewAction.java >




--
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to