Class FreeMarkerTag

java.lang.Object
org.javalite.activeweb.freemarker.FreeMarkerTag
All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel, RequestAccess
Direct Known Subclasses:
ConfirmationTag, CSRFTokenTag, DebugTag, FormTag, LinkToTag, MessageTag, SelectTag, YieldTag

public abstract class FreeMarkerTag extends Object implements freemarker.template.TemplateDirectiveModel, RequestAccess
Convenience class for implementing application - specific tags.
Author:
Igor Polevoy
  • Constructor Details

    • FreeMarkerTag

      public FreeMarkerTag()
  • Method Details

    • logger

      protected org.slf4j.Logger logger()
      Provides a logger to a subclass.
      Returns:
      initialized instance of logger.
    • execute

      public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException
      Specified by:
      execute in interface freemarker.template.TemplateDirectiveModel
      Throws:
      freemarker.template.TemplateException
      IOException
    • get

      protected freemarker.template.TemplateModel get(Object name)
      Gets an object from context - by name.
      Parameters:
      name - name of object
      Returns:
      object or null if not found.
    • getUnwrapped

      protected Object getUnwrapped(Object name)
      Gets an object from context - by name.
      Parameters:
      name - name of object
      Returns:
      object or null if not found.
    • getUnwrapped

      protected <T> T getUnwrapped(Object name, Class<T> clazz)
    • render

      protected abstract void render(Map params, String body, Writer writer) throws Exception
      Implement this method ina concrete subclass.
      Parameters:
      params - this is a list of parameters as provided to tag in HTML.
      body - body of tag
      writer - writer to write output to.
      Throws:
      Exception - if any
    • validateParamsPresence

      protected void validateParamsPresence(Map params, String... names)
      Will throw IllegalArgumentException if a parameter on the list is missing
      Parameters:
      params - as a map passed in by Freemarker
      names - list if valid parameter names for this tag.
    • getContextPath

      protected String getContextPath()
      Returns this applications' context path.
      Returns:
      context path.
    • process

      protected void process(String text, Map params, Writer writer)
      Processes text as a FreeMarker template. Usually used to process an inner body of a tag.
      Parameters:
      text - text of a template.
      params - map with parameters for processing.
      writer - writer to write output to.
    • getAllVariables

      protected Map getAllVariables()
      Returns a map of all variables in scope.
      Returns:
      map of all variables in scope.
    • overrideContext

      public void overrideContext(String context)
      Use to override context of the application. Usually this is done because you need to generate special context related paths due to web server configuration
      Parameters:
      context - this context will be used instead of one provided by Servlet API
    • session

      protected Map session()
      Returns reference to a current session map.
      Returns:
      reference to a current session map.
    • sessionObject

      protected Object sessionObject(String name)
      Convenience method, returns object from session, equivalent of:
       
           session().get(name)
       
       
      Parameters:
      name - name of object,
      Returns:
      session object.