Class UIComponentClassicTagBase
- All Implemented Interfaces:
jakarta.servlet.jsp.tagext.BodyTag,jakarta.servlet.jsp.tagext.IterationTag,jakarta.servlet.jsp.tagext.JspIdConsumer,jakarta.servlet.jsp.tagext.JspTag,jakarta.servlet.jsp.tagext.Tag
- Direct Known Subclasses:
UIComponentELTag,UIComponentTag
public abstract class UIComponentClassicTagBase extends UIComponentTagBase implements jakarta.servlet.jsp.tagext.JspIdConsumer, jakarta.servlet.jsp.tagext.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 Summary
Fields Modifier and Type Field Description protected jakarta.servlet.jsp.tagext.BodyContentbodyContentThebodyContentfor this tag handler.protected jakarta.servlet.jsp.PageContextpageContextThe Jakarta Server PagesPageContextfor the page we are embedded in.protected static StringUNIQUE_ID_PREFIXUsed as the prefix for ids. -
Constructor Summary
Constructors Constructor Description UIComponentClassicTagBase() -
Method Summary
Modifier and Type Method Description protected voidaddChild(UIComponent child)Add the component identifier of the specifiedUIComponentto the list of component identifiers created or located by nestedUIComponentTags processing this request.protected voidaddFacet(String name)Add the facet name of the specified facet to the list of facet names created or located by nestedUIComponentTags processing this request.protected voidaddVerbatimAfterComponent(UIComponentClassicTagBase parentTag, UIComponent verbatim, UIComponent component)Add verbatim as a sibling of component in component in the parent's child list.protected voidaddVerbatimBeforeComponent(UIComponentClassicTagBase parentTag, UIComponent verbatim, UIComponent component)Add verbatim as a sibling of component in component in the parent's child list.protected abstract UIComponentcreateComponent(FacesContext context, String newId)Create and return a new child component of the type returned by callinggetComponentType().protected UIOutputcreateVerbatimComponent()Use theApplicationinstance to create a new component with the following characteristics.protected UIComponentcreateVerbatimComponentFromBodyContent()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.intdoAfterBody()Perform any processing necessary to handle the content implications of CASE 4 in the class description.intdoEndTag()Perform any processing necessary to handle the content implications of CASE 3 in the class description.voiddoInitBody()Prepare for evaluation of the body.intdoStartTag()Perform any processing necessary to find (or create) theUIComponentinstance 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.protected voidencodeBegin()Deprecated.No encoding is done during Jakarta Server Pages page execution.protected voidencodeChildren()Deprecated.No encoding is done during Jakarta Server Pages page execution.protected voidencodeEnd()Deprecated.No encoding is done during Jakarta Server Pages page execution.protected UIComponentfindComponent(FacesContext context)Find and return theUIComponent, from the component tree, that corresponds to this tag handler instance.jakarta.servlet.jsp.tagext.BodyContentgetBodyContent()UIComponentgetComponentInstance()Return theUIComponentinstance that is associated with this tag instance.booleangetCreated()Returntrueif we dynamically created a new component instance during execution of this tag.protected List<String>getCreatedComponents()Returns theListofUIComponentids created or located by nestedUIComponentTags while processing the current request.protected intgetDoAfterBodyValue()Return the flag value that should be returned from thedoAfterBody()method when it is called.protected intgetDoEndValue()Return the flag value that should be returned from thedoEnd()method when it is called.protected intgetDoStartValue()Return the flag value that should be returned from thedoStart()method when it is called.protected FacesContextgetFacesContext()Return theFacesContextinstance for the current request.protected StringgetFacesJspId()If this method has been called before on this tag's useful lifetime (beforerelease()was called), return the previously returned value.protected StringgetFacetName()Return the facet name that we should be stored under, if any; otherwise, return null (indicating that we will be a child component).protected StringgetId()Return theidvalue assigned by the page author.protected intgetIndexOfNextChildTag()Return the index of the next child to be added as a child of this tag.StringgetJspId()jakarta.servlet.jsp.tagext.TaggetParent()Return theTagthat is the parent of this instance.static UIComponentClassicTagBasegetParentUIComponentClassicTagBase(jakarta.servlet.jsp.PageContext context)Locate and return the nearest enclosingUIComponentClassicTagBaseif any; otherwise, returnnull.jakarta.servlet.jsp.JspWritergetPreviousOut()Get theJspWriterfrom ourBodyContent.protected abstract booleanhasBinding()Returntrueif this component has a non-nullbinding attribute.voidrelease()Release any resources allocated during the execution of this tag handler.voidsetBodyContent(jakarta.servlet.jsp.tagext.BodyContent bodyContent)Set thebodyContentfor this tag handler.voidsetId(String id)Set the component identifier for our component.voidsetJspId(String id)Defined onJspIdConsumer.voidsetPageContext(jakarta.servlet.jsp.PageContext pageContext)Set thePageContextof the page containing this tag instance.voidsetParent(jakarta.servlet.jsp.tagext.Tag parent)Set theTagthat is the parent of this instance.protected abstract voidsetProperties(UIComponent component)Override properties and attributes of the specified component, if the corresponding properties of this tag handler instance were explicitly set.protected voidsetupResponseWriter()Deprecated.ViewHandler.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)is now responsible for setting up the response writer.Methods inherited from class jakarta.faces.webapp.UIComponentTagBase
getComponentType, getELContext, getRendererType
-
Field Details
-
UNIQUE_ID_PREFIX
Used as the prefix for ids. This is necessary to avoid uniqueness conflicts with the transient verbatim components.- See Also:
- Constant Field Values
-
bodyContent
protected jakarta.servlet.jsp.tagext.BodyContent bodyContentThe
bodyContentfor this tag handler. -
pageContext
protected jakarta.servlet.jsp.PageContext pageContextThe Jakarta Server Pages
PageContextfor the page we are embedded in.
-
-
Constructor Details
-
UIComponentClassicTagBase
public UIComponentClassicTagBase()
-
-
Method Details
-
getDoStartValue
protected int getDoStartValue() throws jakarta.servlet.jsp.JspExceptionReturn 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:
jakarta.servlet.jsp.JspException- to causedoStart()to throw an exception
-
getDoEndValue
protected int getDoEndValue() throws jakarta.servlet.jsp.JspExceptionReturn 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:
jakarta.servlet.jsp.JspException- to causedoEnd()to throw an exception
-
encodeBegin
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 correspondingUIComponent. This method is called fromdoStartTag(). 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.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 correspondingUIComponent. This method is called fromdoStartTag(). 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.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 correspondingUIComponent. This method is called fromdoStartTag(). 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(jakarta.servlet.jsp.PageContext pageContext)Set the
PageContextof the page containing this tag instance.- Specified by:
setPageContextin interfacejakarta.servlet.jsp.tagext.Tag- Parameters:
pageContext- The enclosingPageContext
-
getParent
public jakarta.servlet.jsp.tagext.Tag getParent()Return the
Tagthat is the parent of this instance.- Specified by:
getParentin interfacejakarta.servlet.jsp.tagext.Tag
-
setParent
public void setParent(jakarta.servlet.jsp.tagext.Tag parent)Set the
Tagthat is the parent of this instance.- Specified by:
setParentin interfacejakarta.servlet.jsp.tagext.Tag- Parameters:
parent- The new parentTag
-
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
ResponseWriterfor the current response, if this has not been done already. -
findComponent
Find and return the
UIComponent, from the component tree, that corresponds to this tag handler instance. If there is no suchUIComponent, create one and add it as a child or facet of theUIComponentassociated with our nearest enclosingUIComponentTag. The process for locating or creating the component is:- If we have previously located this component, return it.
- Locate the parent component by looking for a parent
UIComponentTaginstance, and ask it for its component. If there is no parentUIComponentTaginstance, this tag represents the root component, so get it from the currentTreeand return it. - If this
UIComponentTaginstance has thefacetNameattribute set, ask the parentUIComponentfor a facet with this name. If not found, create one, callsetProperties()with the new component as a parameter, and register it under this name. Return the found or created facetUIComponent. - Determine the component id to be assigned to the new component, as follows: if this
UIComponentTaghas anidattribute set, use that value; otherwise, generate an identifier that is guaranteed to be the same for thisUIComponentevery time this page is processed (i.e. one based on the location of allUIComponentTaginstances without anidattribute set). - Ask the parent
UIComponentfor a child with this identifier. If not found, create one, callsetProperties()with the new component as a parameter, and register it as a child with this identifier. Return the found or created childUIComponent.
When creating a component, the process is:
- Retrieve the component type by calling
UIComponentTagBase.getComponentType() - If the component has a
bindingattribute, create an expression from it, and callApplication.createComponent(java.lang.String)with that expression, theFacesContext, and the component type. Store the expression using the key"binding". - Otherwise, call
Application.createComponent(java.lang.String)with only the component type. - Call
setProperties(). - Add the new component as a child or facet of its parent
- Parameters:
context- theFacesContextfor the current request.- Returns:
- the found component
- Throws:
jakarta.servlet.jsp.JspException- if an unexpected condition arises while finding the component
-
getParentUIComponentClassicTagBase
public static UIComponentClassicTagBase getParentUIComponentClassicTagBase(jakarta.servlet.jsp.PageContext context)Locate and return the nearest enclosing
UIComponentClassicTagBaseif any; otherwise, returnnull.- Parameters:
context-PageContextfor the current page- Returns:
- the parent tag
-
getIndexOfNextChildTag
protected int getIndexOfNextChildTag()Description copied from class:UIComponentTagBaseReturn 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:
getIndexOfNextChildTagin classUIComponentTagBase- Returns:
- the index
-
addChild
Description copied from class:UIComponentTagBaseAdd the component identifier of the specified
UIComponentto the list of component identifiers created or located by nestedUIComponentTags processing this request.- Specified by:
addChildin classUIComponentTagBase- Parameters:
child- New child whose identifier should be added
-
addFacet
Description copied from class:UIComponentTagBaseAdd the facet name of the specified facet to the list of facet names created or located by nested
UIComponentTags processing this request.- Specified by:
addFacetin classUIComponentTagBase- Parameters:
name- Facet name to be added
-
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
Use the
Applicationinstance to create a new component with the following characteristics.componentTypeisjakarta.faces.HtmlOutputText.transientistrue.escapeisfalse.idisFacesContext.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 tagverbatim- the verbatim to add before the componentcomponent- 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 tagverbatim- the verbatim to add after the componentcomponent- the component to be added before the component
-
doStartTag
public int doStartTag() throws jakarta.servlet.jsp.JspExceptionPerform any processing necessary to find (or create) the
UIComponentinstance 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 transientUIOutputcomponent to be created and placed in the tree before theUIComponentinstance for this tag. The value of thisUIOutputcomponent must include anything covered byCASE 1orCASE 2in 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 callingcreateVerbatimComponentFromBodyContent()on the result. It then adds the returned component to the tree before the actual component for this tag instance instance by callingaddVerbatimBeforeComponent(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:
doStartTagin interfacejakarta.servlet.jsp.tagext.Tag- Throws:
jakarta.servlet.jsp.JspException- if an error occurs
-
doEndTag
public int doEndTag() throws jakarta.servlet.jsp.JspExceptionPerform 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
UIComponentthe set of component ids of child components created byUIComponentTaginstances 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
UIComponentthe set of facet names of facets created byUIComponentTaginstances 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:
doEndTagin interfacejakarta.servlet.jsp.tagext.Tag- Throws:
jakarta.servlet.jsp.JspException- if an error occurs
- Retrieve from the
-
release
public void release()Release any resources allocated during the execution of this tag handler.
- Specified by:
releasein interfacejakarta.servlet.jsp.tagext.Tag
-
getDoAfterBodyValue
protected int getDoAfterBodyValue() throws jakarta.servlet.jsp.JspExceptionReturn 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:
jakarta.servlet.jsp.JspException- if an unexpected condition arises while getting the value
-
setBodyContent
public void setBodyContent(jakarta.servlet.jsp.tagext.BodyContent bodyContent)Set the
bodyContentfor this tag handler. This method is invoked by the Jakarta Server Pages page implementation object at most once per action invocation, beforedoInitiBody(). This method will not be invoked for empty tags or for non-empty tags whosedoStartTag()method returnsSKIP_BODYorEVAL_BODY_INCLUDE.- Specified by:
setBodyContentin interfacejakarta.servlet.jsp.tagext.BodyTag- Parameters:
bodyContent- The newBodyContentfor this tag
-
getPreviousOut
public jakarta.servlet.jsp.JspWriter getPreviousOut()Get the
JspWriterfrom ourBodyContent.- Returns:
- the writer
-
getBodyContent
public jakarta.servlet.jsp.tagext.BodyContent getBodyContent() -
doInitBody
public void doInitBody() throws jakarta.servlet.jsp.JspExceptionPrepare 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 whosedoStartTag()method returnsSKIP_BODYorEVAL_BODY_INCLUDE.- Specified by:
doInitBodyin interfacejakarta.servlet.jsp.tagext.BodyTag- Throws:
jakarta.servlet.jsp.JspException- if an error is encountered
-
doAfterBody
public int doAfterBody() throws jakarta.servlet.jsp.JspExceptionPerform any processing necessary to handle the content implications of CASE 4 in the class description.
Return result from
getDoAfterBodyValue()- Specified by:
doAfterBodyin interfacejakarta.servlet.jsp.tagext.IterationTag- Throws:
jakarta.servlet.jsp.JspException- if an error is encountered
-
setId
Set the component identifier for our component. If the argument begins with
UIViewRoot.UNIQUE_ID_PREFIXthrow anIllegalArgumentException- Specified by:
setIdin classUIComponentTagBase- Parameters:
id- The new component identifier. This may not start withUIViewRoot.UNIQUE_ID_PREFIX.- Throws:
IllegalArgumentException- if the argument is non-nulland starts withUIViewRoot.UNIQUE_ID_PREFIX.
-
getId
Return the
idvalue assigned by the page author.- Returns:
- the id of this tag
-
getFacesJspId
If this method has been called before on this tag's useful lifetime (before
release()was called), return the previously returned value. Otherwise, ifgetJspId()returns non-null, prependUNIQUE_ID_PREFIXto thejspIdand return the result.- Returns:
- the value as specified above
-
getCreatedComponents
Returns theListofUIComponentids created or located by nestedUIComponentTags while processing the current request.- Returns:
- the created components
-
setJspId
Defined on
JspIdConsumer. This method is called by the container beforedoStartTag(). 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:
setJspIdin interfacejakarta.servlet.jsp.tagext.JspIdConsumer- Parameters:
id- the container generated id for this tag, guaranteed to be unique within the page.
-
getJspId
-
setProperties
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
UIComponentwas in fact created during the execution of this tag handler instance, and this call will occur BEFORE theUIComponentis 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 propertiesfooandbarwould 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 therenderedproperty is specified for this tag handler instance.rendererType- Set if thegetRendererType()method returns a non-null value.
- Parameters:
component-UIComponentwhose properties are to be overridden
-
createComponent
protected abstract UIComponent createComponent(FacesContext context, String newId) throws jakarta.servlet.jsp.JspExceptionCreate and return a new child component of the type returned by calling
getComponentType(). If thisUIComponentTaghas a non-nullbindingattribute, this is done by callApplication.createComponent(java.lang.String)with the expression created for thebindingattribute, 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-FacesContextfor the current requestnewId- id of the component- Returns:
- the created component
- Throws:
jakarta.servlet.jsp.JspException- if the component cannot be created
-
hasBinding
protected abstract boolean hasBinding()Return
trueif this component has a non-nullbinding attribute. This method is necessary to allow subclasses that expose thebindingproperty 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
Return the
UIComponentinstance 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 ofdoStartTag()anddoEndTag()on this tag instance.- Specified by:
getComponentInstancein classUIComponentTagBase- Returns:
- the component
-
getCreated
public boolean getCreated()Return
trueif 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 ofdoStartTag()anddoEndTag()on this tag instance.- Specified by:
getCreatedin classUIComponentTagBase- Returns:
- the result as specified above
-
getFacesContext
Description copied from class:UIComponentTagBaseReturn the
FacesContextinstance for the current request. This value will be non-nullonly from the beginning ofdoStartTag()through the end ofdoEndTag()for each tag instance.- Specified by:
getFacesContextin classUIComponentTagBase- Returns:
- the
FacesContextfor the current request.
-
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
-