Class SpringTemplateEngine

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware, org.thymeleaf.ITemplateEngine, ISpringTemplateEngine

    public class SpringTemplateEngine
    extends org.thymeleaf.TemplateEngine
    implements ISpringTemplateEngine, org.springframework.context.MessageSourceAware

    Implementation of ISpringTemplateEngine, meant for Spring applications, that establishes by default an instance of SpringStandardDialect as a dialect (instead of an instance of StandardDialect.

    It also configures a SpringMessageResolver as message resolver, and implements the MessageSourceAware interface in order to let Spring automatically setting the MessageSource used at the application (bean needs to have id "messageSource"). If this Spring standard setting needs to be overridden, the setTemplateEngineMessageSource(MessageSource) can be used.

    Since:
    1.0
    Author:
    Daniel Fernández
    • Field Summary

      • Fields inherited from class org.thymeleaf.TemplateEngine

        TIMER_LOGGER_NAME
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getRenderHiddenMarkersBeforeCheckboxes()
      Returns whether the <input type="hidden" ...> marker tags rendered to signal the presence of checkboxes in forms when unchecked should be rendered before the checkbox tag itself, or after (default).
      protected void initializeSpecific()  
      protected void initializeSpringSpecific()
      This method performs additional initializations required for a SpringTemplateEngine subclass instance.
      void setMessageSource​(org.springframework.context.MessageSource messageSource)
      Implementation of the MessageSourceAware.setMessageSource(MessageSource) method at the MessageSourceAware interface, provided so that Spring is able to automatically set the currently configured MessageSource into this template engine.
      void setRenderHiddenMarkersBeforeCheckboxes​(boolean renderHiddenMarkersBeforeCheckboxes)
      Sets whether the <input type="hidden" ...> marker tags rendered to signal the presence of checkboxes in forms when unchecked should be rendered before the checkbox tag itself, or after (default).
      void setTemplateEngineMessageSource​(org.springframework.context.MessageSource templateEngineMessageSource)
      Convenience method for setting the message source that will be used by this template engine, overriding the one automatically set by Spring at the setMessageSource(MessageSource) method.
      • Methods inherited from class org.thymeleaf.TemplateEngine

        addDialect, addDialect, addLinkBuilder, addMessageResolver, addTemplateResolver, clearDialects, clearTemplateCache, clearTemplateCacheFor, getCacheManager, getConfiguration, getDecoupledTemplateLogicResolver, getDialects, getDialectsByPrefix, getEngineContextFactory, getLinkBuilders, getMessageResolvers, getTemplateResolvers, isInitialized, process, process, process, process, process, process, processThrottled, processThrottled, processThrottled, setAdditionalDialects, setCacheManager, setDecoupledTemplateLogicResolver, setDialect, setDialects, setDialectsByPrefix, setEngineContextFactory, setLinkBuilder, setLinkBuilders, setMessageResolver, setMessageResolvers, setTemplateResolver, setTemplateResolvers, threadIndex
      • Methods inherited from interface org.thymeleaf.ITemplateEngine

        getConfiguration, process, process, process, process, process, process, processThrottled, processThrottled, processThrottled
    • Constructor Detail

      • SpringTemplateEngine

        public SpringTemplateEngine()
    • Method Detail

      • setMessageSource

        public void setMessageSource​(org.springframework.context.MessageSource messageSource)

        Implementation of the MessageSourceAware.setMessageSource(MessageSource) method at the MessageSourceAware interface, provided so that Spring is able to automatically set the currently configured MessageSource into this template engine.

        If several MessageSource implementation beans exist, Spring will inject here the one with id "messageSource".

        This property should not be set manually in most scenarios (see setTemplateEngineMessageSource(MessageSource) instead).

        Specified by:
        setMessageSource in interface org.springframework.context.MessageSourceAware
        Parameters:
        messageSource - the message source to be used by the message resolver
      • setTemplateEngineMessageSource

        public void setTemplateEngineMessageSource​(org.springframework.context.MessageSource templateEngineMessageSource)

        Convenience method for setting the message source that will be used by this template engine, overriding the one automatically set by Spring at the setMessageSource(MessageSource) method.

        Specified by:
        setTemplateEngineMessageSource in interface ISpringTemplateEngine
        Parameters:
        templateEngineMessageSource - the message source to be used by the message resolver
        Since:
        2.0.15
      • initializeSpecific

        protected final void initializeSpecific()
        Overrides:
        initializeSpecific in class org.thymeleaf.TemplateEngine
      • getRenderHiddenMarkersBeforeCheckboxes

        public boolean getRenderHiddenMarkersBeforeCheckboxes()

        Returns whether the <input type="hidden" ...> marker tags rendered to signal the presence of checkboxes in forms when unchecked should be rendered before the checkbox tag itself, or after (default).

        (This is just a convenience method, equivalent to calling SpringStandardDialect.getRenderHiddenMarkersBeforeCheckboxes() on the dialect instance itself. It is provided here in order to allow users to modify this behaviour without having to directly create instances of the SpringStandardDialect)

        A number of CSS frameworks and style guides assume that the <label ...> for a checkbox will appear in markup just after the <input type="checkbox" ...> tag itself, and so the default behaviour of rendering an <input type="hidden" ...> after the checkbox can lead to bad application of styles. By tuning this flag, developers can modify this behaviour and make the hidden tag appear before the checkbox (and thus allow the lable to truly appear right after the checkbox).

        Note this hidden field is introduced in order to signal the existence of the field in the form being sent, even if the checkbox is unchecked (no URL parameter is added for unchecked check boxes).

        This flag is set to false by default.

        Returns:
        true if hidden markers should be rendered before the checkboxes, false if not.
        Since:
        3.0.10
      • setRenderHiddenMarkersBeforeCheckboxes

        public void setRenderHiddenMarkersBeforeCheckboxes​(boolean renderHiddenMarkersBeforeCheckboxes)

        Sets whether the <input type="hidden" ...> marker tags rendered to signal the presence of checkboxes in forms when unchecked should be rendered before the checkbox tag itself, or after (default).

        (This is just a convenience method, equivalent to calling SpringStandardDialect.setRenderHiddenMarkersBeforeCheckboxes(boolean) on the dialect instance itself. It is provided here in order to allow users to modify this behaviour without having to directly create instances of the SpringStandardDialect)

        A number of CSS frameworks and style guides assume that the <label ...> for a checkbox will appear in markup just after the <input type="checkbox" ...> tag itself, and so the default behaviour of rendering an <input type="hidden" ...> after the checkbox can lead to bad application of styles. By tuning this flag, developers can modify this behaviour and make the hidden tag appear before the checkbox (and thus allow the lable to truly appear right after the checkbox).

        Note this hidden field is introduced in order to signal the existence of the field in the form being sent, even if the checkbox is unchecked (no URL parameter is added for unchecked check boxes).

        This flag is set to false by default.

        Parameters:
        renderHiddenMarkersBeforeCheckboxes - true if hidden markers should be rendered before the checkboxes, false if not.
        Since:
        3.0.10
      • initializeSpringSpecific

        protected void initializeSpringSpecific()

        This method performs additional initializations required for a SpringTemplateEngine subclass instance. This method is called before the first execution of TemplateEngine.process(String, org.thymeleaf.context.IContext) or TemplateEngine.processThrottled(String, org.thymeleaf.context.IContext) in order to create all the structures required for a quick execution of templates.

        THIS METHOD IS INTERNAL AND SHOULD NEVER BE CALLED DIRECTLY.

        The implementation of this method does nothing, and it is designed for being overridden by subclasses of SpringTemplateEngine.