Templates ae 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 | ||
---|---|---|
| ||
FreeMarker is the default templating engine. The FreeMarker templates are used regardless of what format the view may use. Internally, the JSP, FLT, Velocity tags are all rendered using FreeMarker |
Unless you have some advanced or unusual requirements, template loading is very straight forward. The simple description is this:
...
. |
Template and Themes
Templates are loaded based on the template directory and theme name (see Selecting Themes) and the template directory. The template directory is defined by the webwork action.ui.templateDir
property in action.properties (defaults to template
). This means, by default, if a tag is using the ajax
theme, the following two locations will be searched (in this order):
In the |
---|
...
application | |
---|---|
In the classpath |
...
|
Overriding Templates
Because most of the templates you will need are included in the WebWork jar (the classpath), you may find a few situations where you need to override a particular template to provide behavior that is unique to your application. For example, you might wish to change how select tags render. Rather than creating a brand new template and changing every tag to use that template, you can override the built in select.ftl template by copying the file from in the jar over to a new The default templates provided in the struts-action.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-action.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
directory.
It is easier and better to edit and override an existing template than provide a new one of your own.
Altering Template Loading Behavior
Sometimes it may be important It is possible to load templates template from elsewhere other than the classpath and web app. For example, you might wish to load templates from other locations, like the file system or a URL. This is useful for not only HTML Tags, but also for any result your write. You can do this by consulting 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.
Alternative Template Engines
WebWork The framework provides for template rendering engines other than FreeMarker. We almost never recommend using anything other than FreeMarker templates, if only because WebWork provides templates already written in FreeMarker and not in JSP or Velocity. However, some users, especially advanced users of older versions of WebWork (pre-2.2) may find it necessary to use a different template engine.
Warning |
---|
Alternative template engines are for advanced users. Please use with care! |
(Though, there is rarely a need to use another system!)
Warning | ||
---|---|---|
| ||
Alternative template engines are best left to advanced users with special needs! |
The framework WebWork supports three template engines, which can be controlled by the webwork action.ui.templateSuffix
in action.properties:.
ftl (default) |
---|
...
FreeMarker-based template engine | |
vm |
...
Velocity-based template engine | |
jsp |
...
JSP-based template engine |
If you choose to use vm or jspThe only set of templates and themes provided in the distribution is for FreeMarker. In order to use another template engine, you must implement provide your own templates and themes entirely, which is a large amount of worktemplate and theme for that engine.
Tip | ||
---|---|---|
| ||
Don't feel that you need to rewrite the templates to match your view format. If you need to customize the template, try copying and modifying the FreeMarker template first. Most changes should be obvious.Just because your views aren't written in FreeMarker doesn't mean you can't use the FreeMarker template engine. Again, we strongly discourage you from writing your own templates from scratch. Rather, we recommend you learn a small bit of FreeMarker and extend existing templates |