Class ModelBuilder

  • All Implemented Interfaces:
    GroovyObject

    public class ModelBuilder
    extends BuilderSupport
    Create Thymeleaf 3.0 models using a simplified syntax.
    Author:
    zhanhb, Emanuel Rabina
    • Constructor Detail

      • ModelBuilder

        public ModelBuilder​(ITemplateContext context)
        Constructor, create a new model builder.
        Parameters:
        context -
      • ModelBuilder

        public ModelBuilder​(IModelFactory modelFactory,
                            ElementDefinitions elementDefinitions,
                            TemplateMode templateMode)
        Constructor, create a new model builder.
        Parameters:
        modelFactory -
        elementDefinitions -
        templateMode -
    • Method Detail

      • add

        public void add​(IModel model)
        Appends an existing model to the model being built.
        Parameters:
        model -
      • build

        public IModel build​(Closure<? extends IModel> definition)
        Captures the top `build` call so that it doesn't end up as a node in the final model.
        Parameters:
        definition -
        Returns:
        The model built using the closure definition.
      • createNode

        protected Object createNode​(Object name)
        Create a model for the given HTML element.
        Specified by:
        createNode in class BuilderSupport
        Parameters:
        name - HTML element name.
        Returns:
        New model with the given name.
      • createNode

        protected Object createNode​(Object name,
                                    Object value)
        Create a model for the given HTML element and inner text content.
        Specified by:
        createNode in class BuilderSupport
        Parameters:
        name - HTML element name.
        value - Text content.
        Returns:
        New model with the given name and content.
      • createNode

        protected Object createNode​(Object name,
                                    Map attributes)
        Create a model for the given HTML element and attributes.
        Specified by:
        createNode in class BuilderSupport
        Parameters:
        name - HTML element name.
        attributes - Element attributes.
        Returns:
        New model with the given name and attributes.
      • createNode

        protected IModel createNode​(Object name,
                                    Map attributes,
                                    Object value)
        Create a model for the given HTML element, attributes, and inner text content.
        Specified by:
        createNode in class BuilderSupport
        Parameters:
        name - HTML element name.
        attributes - Element attributes.
        value - Text content.
        Returns:
        New model with the given name, attributes, and content.
      • nodeCompleted

        protected void nodeCompleted​(Object parent,
                                     Object child)
        Link a parent and child node. A child node is appended to a parent by being the last sub-model before the parent close tag.
        Overrides:
        nodeCompleted in class BuilderSupport
        Parameters:
        parent -
        child -
      • setParent

        protected void setParent​(Object parent,
                                 Object child)
        Does nothing. Because models only copy events when added to one another, we can't just add child events at this point - we need to wait until that child has had it's children added, and so on. So the parent/child link is made in the nodeCompleted(java.lang.Object, java.lang.Object) method instead.
        Specified by:
        setParent in class BuilderSupport
        Parameters:
        parent -
        child -