Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
AppFuseSupport
Articles
Articles_cn
Articles_de
Articles_pt
Articles_zh




JSPWiki v2.2.33

[RSS]


Hide Menu

AppFuseVelocity


Difference between version 11 and version 1:

At line 1 changed 1 line.
__Part I:__: [Integrating Velocity into AppFuse|AppFuseVelocity] - A HowTo for adding the Velocity Templating engine to AppFuse applications for rendering views.
__Part I:__ [Integrating Velocity into AppFuse|AppFuseVelocity] - A HowTo for adding the Velocity Templating engine to AppFuse applications for rendering views.
At line 13 added 1 line.
* [7] Build your Velocity Templates
At line 25 changed 1 line.
[{Java2HtmlPlugin
{{{
At line 31 changed 1 line.
}]
}}}
At line 37 changed 3 lines.
{{<lib dir="${velocity.dir}">
<include name="*.jar" />
</lib>}}
<pre>
&lt;lib dir="${velocity.dir}"&gt;
&lt;include name="*.jar" /&gt;
&lt;/lib&gt;
</pre>
At line 43 changed 2 lines.
{{
<war
<pre>
&lt;war
At line 50 changed 1 line.
compress="true">
compress="true"&gt;
At line 52 changed 1 line.
<classes dir="${build.dir}/web/classes"/>
&lt;classes dir="${build.dir}/web/classes"/&gt;
At line 54 changed 2 lines.
<lib file="${dist.dir}/${webapp.name}-common.jar" />
<lib file="${dist.dir}/${webapp.name}-ejb.jar" />
&lt;lib file="${dist.dir}/${webapp.name}-common.jar" /&gt;
&lt;lib file="${dist.dir}/${webapp.name}-ejb.jar" /&gt;
At line 57 changed 25 lines.
<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>
}}
&lt;webinf dir="${struts.dir}" includes="*.xml"/&gt;
&lt;lib dir="${struts.dir}" includes="*.jar"/&gt;
&lt;lib dir="${jstl.dir}/lib"&gt;
&lt;include name="jstl.jar"/&gt;
&lt;include name="standard.jar"/&gt;
&lt;/lib&gt;
&lt;lib file="${log4j.jar}"/&gt;
&lt;lib file="${strutsmenu.jar}"/&gt;
&lt;lib file="${displaytag.jar}"/&gt;
&lt;lib file="${hibernate.jar}"/&gt;
&lt;lib dir="${hibernate.dir}/lib"&gt;
&lt;include name="odmg.jar" /&gt;
&lt;include name="dom4j.jar" /&gt;
&lt;include name="cglib*.jar" /&gt;
&lt;include name="ehcache.jar" /&gt;
&lt;include name="oscache*.jar" /&gt;
&lt;/lib&gt;
&lt;lib file="${statetag.jar}"/&gt;
&lt;lib file="${countrytag.jar}"/&gt;
&lt;lib file="${clickstream.jar}"/&gt;
&lt;lib dir="${velocity.dir}"&gt;
&lt;include name="*.jar" /&gt;
&lt;/lib&gt;
&lt;/war&gt;
</pre>
!!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:
<pre>
&lt;servlet&gt;
&lt;servlet-name&gt;velocity-view&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.apache.velocity.tools.view.servlet.VelocityViewServlet&lt;/servlet-class&gt;
&lt;init-param&gt;
&lt;param-name&gt;org.apache.velocity.toolbox&lt;/param-name&gt;
&lt;param-value&gt;/WEB-INF/toolbox.xml&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;init-param&gt;
&lt;param-name&gt;org.apache.velocity.properties&lt;/param-name&gt;
&lt;param-value&gt;/WEB-INF/velocity.properties&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;load-on-startup&gt;10&lt;/load-on-startup&gt;
&lt;/servlet&gt;
</pre>
Now we must setup the mappings:
Open metadata/web/servlet-mappings.xml and add:
<pre>
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;velocity-view&lt;/servlet-name&gt;
&lt;url-pattern&gt;*.jst&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
The pattern can be anything you like. Velocity usually uses .vm, but I used .jst for Java Server Templates.
!!Configure the Toolbox and VelocityEngine
With 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|http://jakarta.apache.org/velocity/user-guide.html].
First is the velocity.properties:
<pre>
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 = false
</pre>
Very 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):
<pre>
&lt;?xml version="1.0"?&gt;
&lt;toolbox&gt;
&lt;tool&gt;
&lt;key&gt;link&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.StrutsLinkTool&lt;/class&gt;
&lt;/tool&gt;
&lt;tool&gt;
&lt;key&gt;msg&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.MessageTool&lt;/class&gt;
&lt;/tool&gt;
&lt;tool&gt;
&lt;key&gt;errors&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.ErrorsTool&lt;/class&gt;
&lt;/tool&gt;
&lt;tool&gt;
&lt;key&gt;form&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.FormTool&lt;/class&gt;
&lt;/tool&gt;
&lt;/toolbox&gt;
</pre>
!!Modify and ActionForward to point to Velocity [#6]
Change your XDoclet @struts.action-forwards to be something like the following:
{{{
* @struts.action-forward name="edit"
path="/path/to/template/.[vm/jst/whatever]"
}}}
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|http://jakarta.apache.org/velocity/user-guide.html] for Velocity for help with VTL.
''This tutorial was written by [Cameron Gray|http://cameronsweblog.co.uk/page/cameron] - thanks Cameron!''

Back to AppFuseVelocity, or to the Page History.