Versions Compared

Key

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

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

...

Unlike older versions of JSP (in which the JSP Tags are based), FreeMarker allows for dynamic attributes, much like JSP 2.0. You can supply attributes to the tags that the tag doesn't explicitedly support. Those attributes that cannot be applied directly to the tag object will be set to the tag's general-purpose parameters Map.

...

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:

...

What will happen here is that each attribute will be evaluated to a String as best it can. This may involve calling the toString method on the internal FreeMarker objects. In this case, all objects will end up being exactly what you would expect. Then, when the tag runs, the list attribute will be converted from a String to a List using OGNL's advanced collection support.

...

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

Wiki Markup
Notice that the list attribute no longer has quotes around it. Now it will come in to the tag as an object that can't easily be converted to a String. Normally, the tag would just call {{toString}}, which would return "\[WW:1, 2, 3\]" and be unable to be converted back to a List by OGNL. Rather than go through all this back and forth, the frameworks's FreeMarker tag support will recognize collections and not pass them through the normal tag attribute. Instead, the framework will set them directly in the {{parameters}} Map, ready to be consumed by the template.

...

Code Block
xml
xml
<#assign cewolf=JspTaglibs[WW:"/WEB-INF/cewolf.tld"] />
...
<@cewold.xxx ... />

Next: Velocity