| 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 39 changed 1 line. |
| <include name="*.jar" /> |
| <include name="*.jar" /> |
| At line 46 changed 1 line. |
| <war |
| <war |
| At line 82 changed 1 line. |
| </war> |
| </war> |
| At line 85 added 86 lines. |
|
| !!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> |
| <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> |
| </pre> |
|
| Now we must setup the mappings: |
| Open metadata/web/servlet-mappings.xml and add: |
| <pre> |
| <servlet-mapping> |
| <servlet-name>velocity-view</servlet-name> |
| <url-pattern>*.jst</url-pattern> |
| </servlet-mapping> |
| </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> |
| <?xml version="1.0"?> |
|
| <toolbox> |
| <tool> |
| <key>link</key> |
| <scope>request</scope> |
| <class>org.apache.velocity.tools.struts.StrutsLinkTool</class> |
| </tool> |
| <tool> |
| <key>msg</key> |
| <scope>request</scope> |
| <class>org.apache.velocity.tools.struts.MessageTool</class> |
| </tool> |
| <tool> |
| <key>errors</key> |
| <scope>request</scope> |
| <class>org.apache.velocity.tools.struts.ErrorsTool</class> |
| </tool> |
| <tool> |
| <key>form</key> |
| <scope>request</scope> |
| <class>org.apache.velocity.tools.struts.FormTool</class> |
| </tool> |
| </toolbox> |
| </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!'' |