Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
This is version 8.
It is not the current version, and thus it cannot be edited. Part I:: Integrating Velocity into AppFuse - A HowTo for adding the Velocity Templating engine to AppFuse applications for rendering views. About this TutorialThis tutorial will show you how to modify the Ant build script to include Velocity into the build cycle for AppFuse.Table of Contents
Download the prerequistie packages [#1]First we need to get our hands on the VelocityTools packages. These are available from the Jakarta Apache Project.Personally I used Velocity-Tools-1.0-bin, from here. Add the packages to AppFuse's lib structure [#2]The main distribution comes with all sorts of other things, including sample applications, that we don't need. We will extract the precompiled JARs (or make them if you were brave and got a source distribution). The ones we're interested in are the ones that start "velocity-". All of the other dependencies are already in AppFuse.We now need to add this to the the lib folder in your AppFuse source tree. Create a directory lib/velocity-tools-1.0. Now add the following to lib.properties
Modify the build script to include these packages [#3]Now that AppFuse is aware of the new libraries, we need to include them in the build process. Those of you scared of ant build scripts look away now.We must modify the package-web target, to add the following to the lib directives for the war task: <lib dir="${velocity.dir}"> <include name="*.jar" /> </lib>So the full war task definition becomes thus: <war basedir="${webapp.target}" destfile="${webapp.dist}/${webapp.war}" webxml="${build.dir}/web/WEB-INF/web.xml" excludes="**/web.xml,**/hibernate.properties,**/web-test.xml, **/mail.properties,**/cactus.properties" compress="true"> <classes dir="${build.dir}/web/classes"/> <lib file="${dist.dir}/${webapp.name}-common.jar" /> <lib file="${dist.dir}/${webapp.name}-ejb.jar" /> <webinf dir="${struts.dir}" includes="*.xml"/> <lib dir="${struts.dir}" includes="*.jar"/> <lib dir="${jstl.dir}/lib"> <include name="jstl.jar"/> <include name="standard.jar"/> </lib> <lib file="${log4j.jar}"/> <lib file="${strutsmenu.jar}"/> <lib file="${displaytag.jar}"/> <lib file="${hibernate.jar}"/> <lib dir="${hibernate.dir}/lib"> <include name="odmg.jar" /> <include name="dom4j.jar" /> <include name="cglib*.jar" /> <include name="ehcache.jar" /> <include name="oscache*.jar" /> </lib> <lib file="${statetag.jar}"/> <lib file="${countrytag.jar}"/> <lib file="${clickstream.jar}"/> <lib dir="${velocity.dir}"> <include name="*.jar" /> </lib> </war> Add the ViewServlet definition [#4]We know need to make webdoclet generate the appropriate entries for the VelocityViewServlet in web.xml.Open metadata/web/servlets.xml and add the following: <servlet> <servlet-name>velocity-view</servlet-name> <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> <init-param> <param-name>org.apache.velocity.toolbox</param-name> <param-value>/WEB-INF/toolbox.xml</param-value> </init-param> <init-param> <param-name>org.apache.velocity.properties</param-name> <param-value>/WEB-INF/velocity.properties</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> Now we must setup the mappings: Open metadata/web/servlet-mappings.xml and add: <servlet-mapping> <servlet-name>velocity-view</servlet-name> <url-pattern>*.jst</url-pattern> </servlet-mapping>The pattern can be anything you like. Velocity usually uses .vm, but I used .jst for Java Server Templates. Configure the Toolbox and VelocityEngineWith me so far? Good, the last step is easy. We need to create two files in the web/WEB-INF directory to configure Velocity. More information about configuring Velocity can be found on their site.First is the velocity.properties: velocimacro.library = /WEB-INF/VM_global_library.vm velocimacro.permissions.allow.inline = true velocimacro.permissions.allow.inline.to.replace.global = false velocimacro.permissions.allow.inline.local.scope = false velocimacro.context.localscope = falseVery simple, the only thing you may wish to change is velocimacro.library to match where you wish to put your global macros file. Last is toolbox.xml (this configures the Struts tools): <?xml version="1.0"?> Modify and ActionForward to point to Velocity [#6]I haven't got my head around where webdoclet looks for this yet. But basically if you forward out from an Action to anything matching the Velocity uri-pattern. The above tools will contain all the struts resources you'll need. They're embedded in the context as $key, for example $link, $errors, $form and so on.Build your Velocity Templates [#7]See the User Guide for Velocity for help with VTL.
|