Class PropertiesTag

  • All Implemented Interfaces:
    ConditionalTag, PropertySupport, org.apache.commons.jelly.Tag

    public class PropertiesTag
    extends FormBaseTag
    implements PropertySupport

    A tag for creating a map with properties and passing it to a target tag.

    This tag handler class constructs a map that can be populated with properties by tags in the body of this tag. The final map can then either be passed to the parent tag (which must implement the PropertiesSupport interface) or stored as a variable in the Jelly context. The following attributes are supported:

    Attribute Description Optional
    var Here the name of a variable can be specified, under which the resulting map should be stored in the Jelly context. Yes
    ref With this attribute the name of a variable can be specified, which will be used for initializing the internally stored map. This variable must be of type java.util.Map. Newly added properties will be stored in this map. If this attribute is not specified, a new map will be created. Usage of this attribute allows to reuse a map that was created by another PropertiesTag. Yes

    If the var attribute is not specified, the parent tag must implement the PropertiesSupport interface. Otherwise an exception will be thrown because no target for the resulting map can be determined.

    Version:
    $Id: PropertiesTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • PropertiesTag

        public PropertiesTag()
    • Method Detail

      • getVar

        public String getVar()
        Returns the name of a variable, under which the properties are to be stored.
        Returns:
        a variable name for the properties
      • setVar

        public void setVar​(String var)
        Set method of the var attribute.
        Parameters:
        var - the attribute's value
      • getRef

        public String getRef()
        Returns the name of a variable, under which the initial map is stored.
        Returns:
        a avariable with the initial properties map
      • setRef

        public void setRef​(String ref)
        Set method of the ref attribute.
        Parameters:
        ref - the attribute's value
      • processBeforeBody

        protected void processBeforeBody()
                                  throws org.apache.commons.jelly.JellyTagException,
                                         FormBuilderException
        Processes this tag before its body gets executed. This implementation will initialize the internal map with the properties.
        Overrides:
        processBeforeBody in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if attributes have invalid values
        FormBuilderException - if an error occurs
      • process

        protected void process()
                        throws org.apache.commons.jelly.JellyTagException,
                               FormBuilderException
        Processes this tag. This method does the major part of the required work. It locates the target and passes it the map with the properties. If no target can be determined, an exception will be thrown.
        Specified by:
        process in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used
        FormBuilderException - if an error occurs
      • setProperty

        public void setProperty​(String name,
                                Object value)
        Sets a property. This method will be called by tags in the body.
        Specified by:
        setProperty in interface PropertySupport
        Parameters:
        name - the name of the property
        value - the value of the property