Class ComponentTag

  • All Implemented Interfaces:
    Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

    public class ComponentTag
    extends CpnlBodyTagSupport
    a tag to instantiate a bean or model object
    See Also:
    Serialized Form
    • Field Detail

      • variable

        protected String variable
      • varScope

        protected Integer varScope
      • replace

        protected Boolean replace
      • attrPath

        protected String attrPath
      • attrResource

        protected org.apache.sling.api.resource.Resource attrResource
      • component

        protected transient SlingBean component
      • componentWasClosed

        protected transient boolean componentWasClosed
    • Constructor Detail

      • ComponentTag

        public ComponentTag()
    • Method Detail

      • clear

        protected void clear()
        Description copied from class: CpnlBodyTagSupport
        Reset all member variables to the (default) start values. Called prior processing the tag and at release time.
        Overrides:
        clear in class CpnlBodyTagSupport
      • doStartTag

        public int doStartTag()
                       throws javax.servlet.jsp.JspException
        Specified by:
        doStartTag in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doStartTag in class CpnlBodyTagSupport
        Throws:
        javax.servlet.jsp.JspException
      • doEndTag

        public int doEndTag()
                     throws javax.servlet.jsp.JspException
        Specified by:
        doEndTag in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
        Throws:
        javax.servlet.jsp.JspException
      • closeComponent

        protected void closeComponent()
        If necessary, call close on the component, if required. We try to make sure it's called exactly once, since AutoCloseable.close() doesn't guarantee that's idempotent.
      • setId

        public void setId​(String id)
        Configure an var / variable name to store the component in the context
        Overrides:
        setId in class javax.servlet.jsp.tagext.TagSupport
      • setVar

        public void setVar​(String id)
        Configure an var / variable name to store the component in the context
      • getVar

        public String getVar()
      • setType

        public void setType​(String type)
        Component class to instantiate (full notation as in Class.name)
      • getType

        public String getType()
      • setScope

        public void setScope​(String key)
        Determine the varScope (page, request or session) for the component instance attribute
      • setVarScope

        public void setVarScope​(Integer value)
      • getVarScope

        public Integer getVarScope()
      • setReplace

        public void setReplace​(Boolean flag)
        Determine the reuse policy if an appropriate instance is already existing.
        Parameters:
        flag - false - (re)use an appropriate available instance; true - replace each potentially existing instance (default in 'page' context).
      • getReplace

        public Boolean getReplace()
      • setPath

        public void setPath​(String path)
      • setResource

        public void setResource​(org.apache.sling.api.resource.Resource resource)
      • setClose

        public void setClose​(Boolean close)
        Determines whether AutoCloseable models are closed when the tag ends - default true.
      • getClose

        public Boolean getClose()
      • injectServices

        protected void injectServices​(SlingBean component)
                               throws IllegalAccessException
        Inject OSGI services for attributes marked for injection in a new component instance, if not already initialized e.g. by Sling-Models.
        Throws:
        IllegalAccessException
      • retrieveFirstServiceOfType

        protected <T> T retrieveFirstServiceOfType​(Class<T> serviceType,
                                                   String filter)
      • getReplacedAttributes

        protected Map<String,​Object> getReplacedAttributes​(int scope)
        retrieves the registry for one scope
      • setAttribute

        protected void setAttribute​(String key,
                                    Object value,
                                    int scope)
        each attribute set by a tag should use this method for attribute declaration; an existing value with the same key is registered and restored if the tag rendering ends
      • restoreAttributes

        protected void restoreAttributes()
        restores all replaced values and removes all attributes declared in this tag