Versions Compared

Key

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

FreeMarker tags are extensions of the generic Tags provided by the framework. You jump right in just by knowing the generic structure in which the tags can be accessed: <@saf<@s.xxx> ...</@saf@s.xxx>, where xxx is any of the tags supported by the framework.

...

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

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

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

But, wait there's more!

...

Code Block
xml
xml
titleCreating a URL with a query string (JSP)
<saf<s:url value="somePage">
    <saf<s:param name="personId" value="%{personId}"/>
</safs: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)
<@saf<@s.url value="somePage" personId="${personId}"/>

...

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

In the new template, the description is referenced via the parameters Map: "${parameters.description}".

...

Remember that all tag attributes must first be set as Strings - they are then later evaluated (using OGNL) to a different type, such as List, int, or boolean. This generally works just fine, but it can be limiting when using FreeMarker which provides more advanced ways to apply attributes. Suppose the following example:

Code Block
xml
xml
<@saf<@s.select label="Foo label - ${foo}" name="${name}" list="%{{1, 2, 3}}"/>

...

But suppose you wish to use FreeMarker's list or hash support instead? You can do this:

Code Block
xml
xml
<@saf<@s.select label="Foo label - ${foo}" name="${name}" list=[1, 2, 3]/>

...