Class LoopTagSupport
- java.lang.Object
-
- javax.servlet.jsp.tagext.TagSupport
-
- javax.servlet.jsp.jstl.core.LoopTagSupport
-
- All Implemented Interfaces:
java.io.Serializable
,LoopTag
,IterationTag
,JspTag
,Tag
,TryCatchFinally
- Direct Known Subclasses:
ForEachSupport
,ForTokensSupport
public abstract class LoopTagSupport extends TagSupport implements LoopTag, IterationTag, TryCatchFinally
Base support class to facilitate implementation of iteration tags.
Since most iteration tags will behave identically with respect to actual iterative behavior, JSTL provides this base support class to facilitate implementation. Many iteration tags will extend this and merely implement the hasNext() and next() methods to provide contents for the handler to iterate over.
In particular, this base class provides support for:
- Iteration control, based on protected prepare(), next(), and hasNext() methods
- Subsetting (begin, end, step>functionality, including validation of subset parameters for sensibility)
- item retrieval (getCurrent())
- status retrieval (LoopTagStatus)
- exposing attributes (set by var and varStatus attributes)
In providing support for these tasks, LoopTagSupport contains certain control variables that act to modify the iteration. Accessors are provided for these control variables when the variables represent information needed or wanted at translation time (e.g., var, varStatus). For other variables, accessors cannot be provided here since subclasses may differ on their implementations of how those accessors are received. For instance, one subclass might accept a String and convert it into an object of a specific type by using an expression evaluator; others might accept objects directly. Still others might not want to expose such information to outside control.
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
-
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
-
-
Constructor Summary
Constructors Constructor Description LoopTagSupport()
Constructs a new LoopTagSupport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
doAfterBody()
Continues the iteration when appropriate -- that is, if we (a) have more items and (b) don't run over our 'end' (given our 'step').void
doCatch(java.lang.Throwable t)
Rethrows the given Throwable.void
doFinally()
Removes any attributes that this LoopTagSupport set.int
doStartTag()
Begins iterating by processing the first item.java.lang.Object
getCurrent()
Retrieves the current item in the iteration.LoopTagStatus
getLoopStatus()
Retrieves a 'status' object to provide information about the current round of the iteration.void
release()
Releases any resources this LoopTagSupport may have (or inherit).void
setVar(java.lang.String id)
Sets the 'var' attribute.void
setVarStatus(java.lang.String statusId)
Sets the 'varStatus' attribute.-
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.servlet.jsp.tagext.Tag
doEndTag, getParent, setPageContext, setParent
-
-
-
-
Method Detail
-
release
public void release()
Releases any resources this LoopTagSupport may have (or inherit).- Specified by:
release
in interfaceTag
- Overrides:
release
in classTagSupport
- See Also:
Tag.release()
-
doStartTag
public int doStartTag() throws JspException
Begins iterating by processing the first item.- Specified by:
doStartTag
in interfaceTag
- Overrides:
doStartTag
in classTagSupport
- Returns:
- SKIP_BODY
- Throws:
JspException
- if an error occurs while processing this tag- See Also:
Tag.doStartTag()
-
doAfterBody
public int doAfterBody() throws JspException
Continues the iteration when appropriate -- that is, if we (a) have more items and (b) don't run over our 'end' (given our 'step').- Specified by:
doAfterBody
in interfaceIterationTag
- Overrides:
doAfterBody
in classTagSupport
- Returns:
- SKIP_BODY
- Throws:
JspException
- if an error occurs while processing this tag- See Also:
IterationTag.doAfterBody()
-
doFinally
public void doFinally()
Removes any attributes that this LoopTagSupport set.These attributes are intended to support scripting variables with NESTED scope, so we don't want to pollute attribute space by leaving them lying around.
- Specified by:
doFinally
in interfaceTryCatchFinally
-
doCatch
public void doCatch(java.lang.Throwable t) throws java.lang.Throwable
Rethrows the given Throwable.- Specified by:
doCatch
in interfaceTryCatchFinally
- Parameters:
t
- The throwable exception navigating through this tag.- Throws:
java.lang.Throwable
- if the exception is to be rethrown further up the nest chain.
-
getCurrent
public java.lang.Object getCurrent()
Description copied from interface:LoopTag
Retrieves the current item in the iteration. Behaves idempotently; calling getCurrent() repeatedly should return the same Object until the iteration is advanced. (Specifically, calling getCurrent() does not advance the iteration.)- Specified by:
getCurrent
in interfaceLoopTag
- Returns:
- the current item as an object
-
getLoopStatus
public LoopTagStatus getLoopStatus()
Description copied from interface:LoopTag
Retrieves a 'status' object to provide information about the current round of the iteration.- Specified by:
getLoopStatus
in interfaceLoopTag
- Returns:
- The LoopTagStatus for the current LoopTag.
-
setVar
public void setVar(java.lang.String id)
Sets the 'var' attribute.- Parameters:
id
- Name of the exported scoped variable storing the current item of the iteration.
-
setVarStatus
public void setVarStatus(java.lang.String statusId)
Sets the 'varStatus' attribute.- Parameters:
statusId
- Name of the exported scoped variable storing the status of the iteration.
-
-