Versions Compared

Key

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

Table of Contents

Templates ae are loaded first by searching the application and then by searching the classpath. If a template needs to be overridden, an edited copy can be placed in the application, so that is found first.

Info
titleOne for all

FreeMarker is the default templating engine. The FreeMarker templates are used regardless of what format the view may use. Internally, the JSP, FLTFTL, Velocity tags are all rendered using FreeMarker.

...

Templates are loaded based the template directory and theme name (see Selecting Themes). The template directory is defined by the actionstruts.ui.templateDir property in action struts.properties (defaults to template). if If a tag is using the ajax xhtml theme, the following two locations will be searched (in this order):

In the application

/template/ajaxxhtml/template.ftl

In the classpath

/template/ajaxxhtml/template.ftl

(warning) For performance reasons, you may want to prefer the first location, although the second one is more flexible. See Performance Tuning for a discussion on this topic.

Overriding Templates

The default templates provided in the struts-actioncore.jar should suit the needs of many applications. However, if a template needs to be modified, it's easy to plug in a new version. Extract the template you need to change from the struts-actioncore.jar, make the modifications, and save the updated copy to /template/$theme/$template.ftl. If you are using the xhmtl theme and need to change how the select tags render, edit that template and save it to /template/xhtml/select.ftl.

(warning) It is easier and better to edit and override an existing template than provide a new one of your own.

Extending Templates

To extends templates from a particular theme, put file called theme.properties in the $template directory. An example of the content of theme.properties could be as follows:-

Code Block
titletheme.properties

parent=xhtml

In this case, if one wants to create a theme called myTheme and wanted to extends off xhtml theme, one could put create a $templateDir/myTheme/ directory and put a theme.properties file with content as above in it.

Altering Template Loading

...

Behaviour

It is possible to load template from other locations, like the file system or a URL. Loading templates from alternate locations can be useful not only for tags, but for custom results. For details, see the FreeMarker documentation and consult the section on extending the FreeMarkerManager.

...

The framework supports three template engines, which can be controlled by the actionstruts.ui.templateSuffix in action struts.properties.

ftl (default)

FreeMarker-based template engine

vm

Velocity-based template engine

jsp

JSP-based template engine

...