Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » views » freemarker » [javadoc | source]
org.apache.struts2.views.freemarker
public class: FreemarkerResult [javadoc | source]
java.lang.Object
   org.apache.struts2.dispatcher.StrutsResultSupport
      org.apache.struts2.views.freemarker.FreemarkerResult

All Implemented Interfaces:
    com.opensymphony.xwork2.Result, StrutsStatics

Renders a view using the Freemarker template engine.

The FreemarkarManager class configures the template loaders so that the template location can be either

This result type takes the following parameters: Example:


<result name="success" type="freemarker">foo.ftl</result>


Field Summary
protected  ActionInvocation invocation     
protected  Configuration configuration     
protected  ObjectWrapper wrapper     
protected  FreemarkerManager freemarkerManager     
protected  String location     
Fields inherited from org.apache.struts2.dispatcher.StrutsResultSupport:
DEFAULT_PARAM
Constructor:
 public FreemarkerResult() 
 public FreemarkerResult(String location) 
Method from org.apache.struts2.views.freemarker.FreemarkerResult Summary:
createModel,   deduceLocale,   doExecute,   getConfiguration,   getContentType,   getObjectWrapper,   getWriter,   isWriteIfCompleted,   postTemplateProcess,   preTemplateProcess,   setContentType,   setFreemarkerManager,   setWriteIfCompleted,   setWriter
Methods from org.apache.struts2.dispatcher.StrutsResultSupport:
conditionalParse,   doExecute,   execute,   getLastFinalLocation,   getLocation,   setEncode,   setLocation,   setParse
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts2.views.freemarker.FreemarkerResult Detail:
 protected TemplateModel createModel() throws TemplateModelException 
    Build the instance of the ScopesHashModel, including JspTagLib support

    Objects added to the model are

    • Application - servlet context attributes hash model
    • JspTaglibs - jsp tag lib factory model
    • Request - request attributes hash model
    • Session - session attributes hash model
    • request - the HttpServletRequst object for direct access
    • response - the HttpServletResponse object for direct access
    • stack - the OgnLValueStack instance for direct access
    • ognl - the instance of the OgnlTool
    • action - the action itself
    • exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)
    • struts - instance of the StrutsUtil class
 protected Locale deduceLocale() 
    Returns the locale used for the Configuration#getTemplate(String, Locale) call. The base implementation simply returns the locale setting of the action (assuming the action implements LocaleProvider ) or, if the action does not the configuration's locale is returned. Override this method to provide different behaviour,
 public  void doExecute(String locationArg,
    ActionInvocation invocation) throws IOException, TemplateException 
    Execute this result, using the specified template locationArg.

    The template locationArg has already been interoplated for any variable substitutions

    this method obtains the freemarker configuration and the object wrapper from the provided hooks. It them implements the template processing workflow by calling the hooks for preTemplateProcess and postTemplateProcess

 protected Configuration getConfiguration() throws TemplateException 
    This method is called from #doExecute(String, ActionInvocation) to obtain the FreeMarker configuration object that this result will use for template loading. This is a hook that allows you to custom-configure the configuration object in a subclass, or to fetch it from an IoC container.

    The default implementation obtains the configuration from the ConfigurationManager instance.

 public String getContentType() 
    allow parameterization of the contentType the default being text/html
 protected ObjectWrapper getObjectWrapper() 
 protected Writer getWriter() throws IOException 
    The default writer writes directly to the response writer.
 public boolean isWriteIfCompleted() 
 protected  void postTemplateProcess(Template template,
    TemplateModel data) throws IOException 
    the default implementation of postTemplateProcess applies the contentType parameter
 protected boolean preTemplateProcess(Template template,
    TemplateModel model) throws IOException 
    Called before the execution is passed to template.process(). This is a generic hook you might use in subclasses to perform a specific action before the template is processed. By default does nothing. A typical action to perform here is to inject application-specific objects into the model root
 public  void setContentType(String aContentType) 
 public  void setFreemarkerManager(FreemarkerManager mgr) 
 public  void setWriteIfCompleted(boolean writeIfCompleted) 
    Writes to the stream only when template processing completed successfully
 public  void setWriter(Writer writer)