Class UIComponentClassicTagBase

java.lang.Object
jakarta.faces.webapp.UIComponentTagBase
jakarta.faces.webapp.UIComponentClassicTagBase
All Implemented Interfaces:
BodyTag, IterationTag, JspIdConsumer, JspTag, Tag
Direct Known Subclasses:
UIComponentELTag, UIComponentTag

public abstract class UIComponentClassicTagBase extends UIComponentTagBase implements JspIdConsumer, BodyTag

UIComponentTagBase is the base class for all Jakarta Server Pages tags that use the "classic" Jakarta Server Pages tag interface that correspond to a UIComponent instance in the view. In Faces 1.2, all component tags are BodyTag instances to allow for the execution of the page to build the component tree, but not render it. Rendering happens only after the component tree is completely built.

UIComponentTag extends UIComponentClassicTagBase to add support for properties that conform to the Faces 1.1 Expression Language.

UIComponentELTag extends UIComponentClassicTagBase class to add support for properties that conform to the Expression Language API.

The default implementation allows the proper interweaving of template text, non-Faces Jakarta Server Pages tag output, and Faces component tag output in the same page, as expected by the page author.

The CASE markers in the following example will be cited in the method descriptions of this class.

  • CASE 1 describes template text and/or non-component custom tag output occurring as the child of a component tag, but before the first component tag child of that component tag.

  • CASE 2 describes template text and/or non-component custom tag output occurring between two sibling component tags.

  • CASE 3 describes template text and/or non-component custom tag output occurring as the child content of an <f:verbatim> tag at any point in the page.

  • CASE 4 describes template text and/or non-component custom tag output occurring between the last child component tag and its enclosing parent component tag's end tag.

 

 <h:panelGrid style="color:red" border="4" columns="2">
 CASE 1
 <h:outputText value="component 1"/>
 CASE 2
 <h:outputText value="component 2"/>
 <f:verbatim>CASE 3</f:verbatim>
 <c:out value="${pageScope.CASE4}" />
 </h:panelGrid>

 
 

The preceding arrangement of faces component tags, must yield markup that will render identically to the following (assuming that ${pageScope.CASE4} evaluates to "CASE 4" without the quotes).

 

 <table border="4" style="color:red">

 <tbody>

 <tr><td>CASE 1</td></tr> <tr><td>component 1</td></tr>

 <tr><td>CASE 2</td> <tr><td>component 2</td></tr>

 <tr><td>CASE 3</td> <td>CASE 4</td></tr>

 </tbody>

 </table>

 
 
  • Field Details

    • UNIQUE_ID_PREFIX

      protected static final String UNIQUE_ID_PREFIX
      Used as the prefix for ids. This is necessary to avoid uniqueness conflicts with the transient verbatim components.
      See Also:
    • bodyContent

      protected BodyContent bodyContent

      The bodyContent for this tag handler.

    • pageContext

      protected PageContext pageContext

      The Jakarta Server Pages PageContext for the page we are embedded in.

  • Constructor Details

    • UIComponentClassicTagBase

      public UIComponentClassicTagBase()
  • Method Details

    • getDoStartValue

      protected int getDoStartValue() throws JspException

      Return the flag value that should be returned from the doStart() method when it is called. Subclasses may override this method to return the appropriate value.

      Returns:
      the value to return from doStart()
      Throws:
      JspException - to cause doStart() to throw an exception
    • getDoEndValue

      protected int getDoEndValue() throws JspException

      Return the flag value that should be returned from the doEnd() method when it is called. Subclasses may override this method to return the appropriate value.

      Returns:
      the value to return from doEnd()
      Throws:
      JspException - to cause doEnd() to throw an exception
    • encodeBegin

      @Deprecated protected void encodeBegin() throws IOException
      Deprecated.
      No encoding is done during Jakarta Server Pages page execution. Encoding is deferred until the page has completed executing to allow the entire tree to be built before any encoding occurs.

      Delegate to the encodeBegin() method of our corresponding UIComponent. This method is called from doStartTag(). Normally, delegation occurs unconditionally; however, this method is abstracted out so that advanced tags can conditionally perform this call.

      Throws:
      IOException - if an input/output error occurs
    • encodeChildren

      @Deprecated protected void encodeChildren() throws IOException
      Deprecated.
      No encoding is done during Jakarta Server Pages page execution. Encoding is deferred until the page has completed executing to allow the entire tree to be built before any encoding occurs.

      Delegate to the encodeChildren() method of our corresponding UIComponent. This method is called from doStartTag(). Normally, delegation occurs unconditionally; however, this method is abstracted out so that advanced tags can conditionally perform this call.

      Throws:
      IOException - if an input/output error occurs
    • encodeEnd

      @Deprecated protected void encodeEnd() throws IOException
      Deprecated.
      No encoding is done during Jakarta Server Pages page execution. Encoding is deferred until the page has completed executing to allow the entire tree to be built before any encoding occurs.

      Delegate to the encodeEnd() method of our corresponding UIComponent. This method is called from doStartTag(). Normally, delegation occurs unconditionally; however, this method is abstracted out so that advanced tags can conditionally perform this call.

      Throws:
      IOException - if an input/output error occurs
    • setPageContext

      public void setPageContext(PageContext pageContext)

      Set the PageContext of the page containing this tag instance.

      Specified by:
      setPageContext in interface Tag
      Parameters:
      pageContext - The enclosing PageContext
    • getParent

      public Tag getParent()

      Return the Tag that is the parent of this instance.

      Specified by:
      getParent in interface Tag
      Returns:
      the current parent, or null if none.
      See Also:
    • setParent

      public void setParent(Tag parent)

      Set the Tag that is the parent of this instance.

      Specified by:
      setParent in interface Tag
      Parameters:
      parent - The new parent Tag
    • setupResponseWriter

      @Deprecated protected void setupResponseWriter()
      Deprecated.
      ViewHandler.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot) is now responsible for setting up the response writer. This method is now a no-op.

      Set up the ResponseWriter for the current response, if this has not been done already.

    • findComponent

      protected UIComponent findComponent(FacesContext context) throws JspException

      Find and return the UIComponent, from the component tree, that corresponds to this tag handler instance. If there is no such UIComponent, create one and add it as a child or facet of the UIComponent associated with our nearest enclosing UIComponentTag. The process for locating or creating the component is:

      1. If we have previously located this component, return it.
      2. Locate the parent component by looking for a parent UIComponentTag instance, and ask it for its component. If there is no parent UIComponentTag instance, this tag represents the root component, so get it from the current Tree and return it.
      3. If this UIComponentTag instance has the facetName attribute set, ask the parent UIComponent for a facet with this name. If not found, create one, call setProperties() with the new component as a parameter, and register it under this name. Return the found or created facet UIComponent.
      4. Determine the component id to be assigned to the new component, as follows: if this UIComponentTag has an id attribute set, use that value; otherwise, generate an identifier that is guaranteed to be the same for this UIComponent every time this page is processed (i.e. one based on the location of all UIComponentTag instances without an id attribute set).
      5. Ask the parent UIComponent for a child with this identifier. If not found, create one, call setProperties() with the new component as a parameter, and register it as a child with this identifier. Return the found or created child UIComponent.

      When creating a component, the process is:

      1. Retrieve the component type by calling UIComponentTagBase.getComponentType()
      2. If the component has a binding attribute, create an expression from it, and call Application.createComponent(java.lang.String) with that expression, the FacesContext, and the component type. Store the expression using the key "binding".
      3. Otherwise, call Application.createComponent(java.lang.String) with only the component type.
      4. Call setProperties().
      5. Add the new component as a child or facet of its parent
      Parameters:
      context - the FacesContext for the current request.
      Returns:
      the found component
      Throws:
      JspException - if an unexpected condition arises while finding the component
    • getParentUIComponentClassicTagBase

      public static UIComponentClassicTagBase getParentUIComponentClassicTagBase(PageContext context)

      Locate and return the nearest enclosing UIComponentClassicTagBase if any; otherwise, return null.

      Parameters:
      context - PageContext for the current page
      Returns:
      the parent tag
    • getIndexOfNextChildTag

      protected int getIndexOfNextChildTag()
      Description copied from class: UIComponentTagBase

      Return the index of the next child to be added as a child of this tag. The default implementation maintains a list of created components and returns the size of the list.

      Specified by:
      getIndexOfNextChildTag in class UIComponentTagBase
      Returns:
      the index
    • addChild

      protected void addChild(UIComponent child)
      Description copied from class: UIComponentTagBase

      Add the component identifier of the specified UIComponent to the list of component identifiers created or located by nested UIComponentTags processing this request.

      Specified by:
      addChild in class UIComponentTagBase
      Parameters:
      child - New child whose identifier should be added
    • addFacet

      protected void addFacet(String name)
      Description copied from class: UIComponentTagBase

      Add the facet name of the specified facet to the list of facet names created or located by nested UIComponentTags processing this request.

      Specified by:
      addFacet in class UIComponentTagBase
      Parameters:
      name - Facet name to be added
    • createVerbatimComponentFromBodyContent

      protected UIComponent createVerbatimComponentFromBodyContent()

      Create a transient UIOutput component from the body content, of this tag instance or return null if there is no body content, the body content is whitespace, or the body content is a comment.

      Returns:
      the component
    • createVerbatimComponent

      protected UIOutput createVerbatimComponent()

      Use the Application instance to create a new component with the following characteristics.

      componentType is jakarta.faces.HtmlOutputText.

      transient is true.

      escape is false.

      id is FacesContext.getViewRoot().createUniqueId()

      Returns:
      the component
    • addVerbatimBeforeComponent

      protected void addVerbatimBeforeComponent(UIComponentClassicTagBase parentTag, UIComponent verbatim, UIComponent component)

      Add verbatim as a sibling of component in component in the parent's child list. verbatim is added to the list at the position immediatly preceding component.

      Parameters:
      parentTag - the parent tag
      verbatim - the verbatim to add before the component
      component - the component to be added after the component
    • addVerbatimAfterComponent

      protected void addVerbatimAfterComponent(UIComponentClassicTagBase parentTag, UIComponent verbatim, UIComponent component)

      Add verbatim as a sibling of component in component in the parent's child list. verbatim is added to the list at the position immediatly following component.

      Parameters:
      parentTag - the parent tag
      verbatim - the verbatim to add after the component
      component - the component to be added before the component
    • doStartTag

      public int doStartTag() throws JspException

      Perform any processing necessary to find (or create) the UIComponent instance in the view corresponding to this tag instance in the page and, if and only if a component was created, insert it into the tree at the proper location as expected by the page author. Secondarily, cause a transient UIOutput component to be created and placed in the tree before the UIComponent instance for this tag. The value of this UIOutput component must include anything covered by CASE 1 or CASE 2 in the class description.

      The default implementation, which is intended to be sufficient for most components, implements this secondary requirement by calling getParentUIComponentClassicTagBase(jakarta.servlet.jsp.PageContext), and calling createVerbatimComponentFromBodyContent() on the result. It then adds the returned component to the tree before the actual component for this tag instance instance by calling addVerbatimBeforeComponent(jakarta.faces.webapp.UIComponentClassicTagBase, jakarta.faces.component.UIComponent, jakarta.faces.component.UIComponent).

      Before returning, the component is pushed onto the component stack for this response to enable the getParentUIComponentClassicTagBase(jakarta.servlet.jsp.PageContext) method to work properly.

      The flag value to be returned is acquired by calling the getDoStartValue() method, which tag subclasses may override if they do not want the default value.

      Specified by:
      doStartTag in interface Tag
      Returns:
      EVAL_BODY_INCLUDE if the tag wants to process body, SKIP_BODY if it does not want to process it.
      Throws:
      JspException - if an error occurs
      See Also:
    • doEndTag

      public int doEndTag() throws JspException

      Perform any processing necessary to handle the content implications of CASE 3 in the class description.

      The default implementation, which is intended to be sufficient for most components, calls createVerbatimComponentFromBodyContent() on this instance and adds it as a child of the component for this tag's component at the end of the child list. In addition, the following housekeeping steps are taken.

      • Retrieve from the UIComponent the set of component ids of child components created by UIComponentTag instances the last time this page was processed (if any). Compare it to the list of children created during this page processing pass, and remove all children present in the old list but not the new. Save the new list as a component attribute so that it gets saved as part of the component's state.
      • Retrieve from the UIComponent the set of facet names of facets created by UIComponentTag instances the last time this page was processed (if any). Compare it to the list of facets created during this page processing pass, and remove all facets present in the old list but not the new. Save the new list as a component attribute so that it gets saved as part of the component's state.
      • Release all references to the component, and pop it from the component stack for this response, removing the stack if this was the outermost component.

      The flag value to be returned is acquired by calling the getDoEndValue() method, which tag subclasses may override if they do not want the default value.

      Specified by:
      doEndTag in interface Tag
      Returns:
      indication of whether to continue evaluating the JSP page.
      Throws:
      JspException - if an error occurs
    • release

      public void release()

      Release any resources allocated during the execution of this tag handler.

      Specified by:
      release in interface Tag
    • getDoAfterBodyValue

      protected int getDoAfterBodyValue() throws JspException

      Return the flag value that should be returned from the doAfterBody() method when it is called. Subclasses may override this method to return the appropriate value.

      Returns:
      the value to return from doAfterBody()
      Throws:
      JspException - if an unexpected condition arises while getting the value
    • setBodyContent

      public void setBodyContent(BodyContent bodyContent)

      Set the bodyContent for this tag handler. This method is invoked by the Jakarta Server Pages page implementation object at most once per action invocation, before doInitiBody(). This method will not be invoked for empty tags or for non-empty tags whose doStartTag() method returns SKIP_BODY or EVAL_BODY_INCLUDE.

      Specified by:
      setBodyContent in interface BodyTag
      Parameters:
      bodyContent - The new BodyContent for this tag
      See Also:
    • getPreviousOut

      public JspWriter getPreviousOut()

      Get the JspWriter from our BodyContent.

      Returns:
      the writer
    • getBodyContent

      public BodyContent getBodyContent()
    • doInitBody

      public void doInitBody() throws JspException

      Prepare for evaluation of the body. This method is invoked by the Jakarta Server Pages page implementation object after setBodyContent() and before the first time the body is to be evaluated. This method will not be invoked for empty tags or for non-empty tags whose doStartTag() method returns SKIP_BODY or EVAL_BODY_INCLUDE.

      Specified by:
      doInitBody in interface BodyTag
      Throws:
      JspException - if an error is encountered
      See Also:
    • doAfterBody

      public int doAfterBody() throws JspException

      Perform any processing necessary to handle the content implications of CASE 4 in the class description.

      Return result from getDoAfterBodyValue()

      Specified by:
      doAfterBody in interface IterationTag
      Returns:
      whether additional evaluations of the body are desired
      Throws:
      JspException - if an error is encountered
    • setId

      public void setId(String id)

      Set the component identifier for our component. If the argument begins with UIViewRoot.UNIQUE_ID_PREFIX throw an IllegalArgumentException

      Specified by:
      setId in class UIComponentTagBase
      Parameters:
      id - The new component identifier. This may not start with UIViewRoot.UNIQUE_ID_PREFIX.
      Throws:
      IllegalArgumentException - if the argument is non-null and starts with UIViewRoot.UNIQUE_ID_PREFIX.
    • getId

      protected String getId()

      Return the id value assigned by the page author.

      Returns:
      the id of this tag
    • getFacesJspId

      protected String getFacesJspId()

      If this method has been called before on this tag's useful lifetime (before release() was called), return the previously returned value. Otherwise, if getJspId() returns non-null, prepend UNIQUE_ID_PREFIX to the jspId and return the result.

      Returns:
      the value as specified above
    • getCreatedComponents

      protected List<String> getCreatedComponents()
      Returns the List of UIComponent ids created or located by nested UIComponentTags while processing the current request.
      Returns:
      the created components
    • setJspId

      public void setJspId(String id)

      Defined on JspIdConsumer. This method is called by the container before doStartTag(). The argument is guaranteed to be unique within the page.

      IMPLEMENTATION NOTE: This method will detect where we are in an include and assign a unique ID for each include in a particular 'logical page'. This allows us to avoid possible duplicate ID situations for included pages that have components without explicit IDs.

      Specified by:
      setJspId in interface JspIdConsumer
      Parameters:
      id - the container generated id for this tag, guaranteed to be unique within the page.
    • getJspId

      public String getJspId()
    • setProperties

      protected abstract void setProperties(UIComponent component)

      Override properties and attributes of the specified component, if the corresponding properties of this tag handler instance were explicitly set. This method must be called ONLY if the specified UIComponent was in fact created during the execution of this tag handler instance, and this call will occur BEFORE the UIComponent is added to the view.

      Tag subclasses that want to support additional set properties must ensure that the base class setProperties() method is still called. A typical implementation that supports extra properties foo and bar would look something like this:

       protected void setProperties(UIComponent component) {
           super.setProperties(component);
           if (foo != null) {
               component.setAttribute("foo", foo);
           }
           if (bar != null) {
               component.setAttribute("bar", bar);
           }
       }
       

      The default implementation overrides the following properties:

      • rendered - Set if a value for the rendered property is specified for this tag handler instance.
      • rendererType - Set if the getRendererType() method returns a non-null value.
      Parameters:
      component - UIComponent whose properties are to be overridden
    • createComponent

      protected abstract UIComponent createComponent(FacesContext context, String newId) throws JspException

      Create and return a new child component of the type returned by calling getComponentType(). If this UIComponentTag has a non-null binding attribute, this is done by call Application.createComponent(java.lang.String) with the expression created for the binding attribute, and the expression will be stored on the component. Otherwise, Application.createComponent(java.lang.String) is called with only the component type. Finally, initialize the components id and other properties.

      Parameters:
      context - FacesContext for the current request
      newId - id of the component
      Returns:
      the created component
      Throws:
      JspException - if the component cannot be created
    • hasBinding

      protected abstract boolean hasBinding()

      Return true if this component has a non-null binding attribute. This method is necessary to allow subclasses that expose the binding property as an Faces 1.1 style Expression Language property as well as subclasses that expose it as a Jakarta Expression Language API property.

      Returns:
      whether or not this component has a binding attribute
    • getComponentInstance

      public UIComponent getComponentInstance()

      Return the UIComponent instance that is associated with this tag instance. This method is designed to be used by tags nested within this tag, and only returns useful results between the execution of doStartTag() and doEndTag() on this tag instance.

      Specified by:
      getComponentInstance in class UIComponentTagBase
      Returns:
      the component
    • getCreated

      public boolean getCreated()

      Return true if we dynamically created a new component instance during execution of this tag. This method is designed to be used by tags nested within this tag, and only returns useful results between the execution of doStartTag() and doEndTag() on this tag instance.

      Specified by:
      getCreated in class UIComponentTagBase
      Returns:
      the result as specified above
    • getFacesContext

      protected FacesContext getFacesContext()
      Description copied from class: UIComponentTagBase

      Return the FacesContext instance for the current request. This value will be non-null only from the beginning of doStartTag() through the end of doEndTag() for each tag instance.

      Specified by:
      getFacesContext in class UIComponentTagBase
      Returns:
      the FacesContext for the current request.
    • getFacetName

      protected String getFacetName()

      Return the facet name that we should be stored under, if any; otherwise, return null (indicating that we will be a child component).

      Returns:
      the name of the facet