...
Code Block |
---|
title | freemarker.properties |
---|
|
default_encoding=ISO-8859-1
template_update_delay=5
locale=no_NO
|
Using Struts tags
Tags distributed with Struts are automatically available to FreeMarker templates. To use any tag add "@s.
" in front of the tag name. Like:
Code Block |
---|
title | Using Struts tags on FreeMarker templates |
---|
|
<@s.if test="printName">
<@s.property value="myBeanProperty" />
</@s.if>
|
Using JSP tags
To use JSP tags that are not part of Struts you have to import the tld. There are two ways of making a tld available to FreeMarker templates:
- Declare the tld on web.xml
- Use FreeMarker's "
assign
" directive. When using the "assign
" directive, provide the full path to the tld file, like:
Code Block |
---|
| XML |
---|
| XML |
---|
title | Using JSP tags on FreeMarker templates |
---|
|
<#assign ex=JspTaglibs["/WEB-INF/example.tld"] />
<@ex.mytag text="hello" />
|
FreeMarker alternative syntax
FreeMarker by default uses the "<#directive />" syntax. FreeMarker supports an alternative syntax, where [ and ] are used instead of < and >. To enable the alternative syntax, add #ftl at the beginning of the template. The alternative syntax makes it easier to differentiate between FreeMarker directives, and JSP or HTML tags.
Code Block |
---|
| HTML |
---|
| HTML |
---|
title | Use alternative syntax |
---|
|
[#ftl]
<html>
<head>FreeMarker Example</head>
<body>
<h1>Alternative Syntax</h1>
[@s.if test="printName"]
[@s.property value="myBeanProperty" /]
[/@s.if]
</body>
</html>
|
String and Non String Values on tags
In FreeMarker it is incorrect to quote non string values. If a value is quoted, then an string will be passed, instead of the expected object, causing an exception. For example, the "textarea" tag expects the attributes "rows" and "cols" of type Integer:
Code Block |
---|
| Do not quote non string values in tag attributes! |
---|
| Do not quote non string values in tag attributes! |
---|
|
<@s.textarea label="'Details'" name="'details'" rows=5 cols=40 />
|