Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Update parent page

...

Note

FreeMarker is very similar to Velocity, as both are template languages that can be used outside of a Servlet container. The WebWork team recommends FreeMarker over Velocity simply because FreeMarker has better error reporting, support for JSP tags, and slightly better features. However, both are good alternatives to JSP.

 

Getting Started

Getting started with FreeMarker is as simple as ensuring all the dependencies are included in your project's classpath. This typically requires simply freemarker.jar. Other than that, action-default.xml already configures the FreeMarker Result needed to map your actions to your templates. You may now try out the following xwork.xml configuration:

...

Code Block
<#if Application.myApplicationAttribute?exists>
     ${Application.myApplicationAttribute}
</#if>

or

Code Block
  <@saf.property value="%{#application.myApplicationAttribute}" />

...

Code Block
<#if Session.mySessionAttribute?exists>
     ${Session.mySessionAttribute}
</#if>

or

Code Block
  <@saf.property value="%{#session.mySessionAttribute}" />

...

Code Block
<#if Request.myRequestAttribute?exists>
      ${Request.myRequestAttribute}
</#if>

or

Code Block
   <@saf.property value="%{#request.myRequestAttribute}" />

...

Assuming there's a request parameter myParameter (eg. http://host/myApp/myAction.action?myParameter=oneImage Removed).

Code Block
<#if Parameters.myParameter?exists>
     ${Parameters.myParameter}
</#if>

or

Code Block
  <@saf.property value="%{#parameters.myParameter}" />

...

Assuming there's a parameter with the name myContextParam in SAF context.

Code Block
   ${stack.findValue('#myContextParam')}

or

Code Block
  <@saf.property value="%{#myContextParam}" />

...