Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

For example, in JSP you might create a form using Struts tags.

Code Block
xml
xml
titleJSP Formxml
<s:form action="updatePerson">
    <s:textfield label="First name" name="firstName"/>
    <s:submit value="Update"/>
</s:form>

In FreeMarker the same form can also be built using Struts tags.

Code Block
xml
xml
titleFTL Formxml
<@s.form action="updatePerson">
    <@s.textfield label="First name" name="firstName"/>
    <@s.submit value="Update"/>
</@s.form>

...

Suppose we wanted to build an URL in a JSP. The URL needs to take an arbitary parameter to the query string, that (being arbitary) isn't specified on the URL tag. In a JSP, we'd have to use the url and param tags together.

Code Block
xml
xml
titleCreating a URL with a query string (JSP)xml
<s:url value="somePage">
    <s:param name="personId" value="%{personId}"/>
</s:url>

In FreeMarker, we can pass the arbitrary parameter directly and create the URL in one simple statement.

Code Block
xml
xml
titleCreating a URL with a query string (FTL)xml
<@s.url value="somePage" personId="${personId}"/>

...

Suppose you created a "three column" theme to replace the typical two column theme (xhtml). You might want an additional parameter to display in the third column called "description". Using FreeMarker, you can just pop the description attribute into the textfield tag, no fuss, no muss.

Code Block
xml
xml
titlePassing an attribute to the templatexml
<@s.form action="updatePerson">
    <@s.textfield label="First name" name="firstName" description="..."/>
    <@s.submit value="Update"/>
</@s.form>

...

While the framework provides native FreeMarker Tags, you might wish to use other third-party tags that are only available for JSP. Fortunately, FreeMarker has the ability to run JSP tags. To do so, you must include the JspSupportServlet in the application's web.xml, as this allows the FreeMarker integration to get access to the required objects needed to emulate a JSP taglib container.

Code Block
xml
xml
titleAdding JspSupportSerlvet to web.xmlxml
<servlet>
    <servlet-name>JspSupportServlet</servlet-name>
    <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

...