Class ForEachSupport
- java.lang.Object
-
- javax.servlet.jsp.tagext.TagSupport
-
- javax.servlet.jsp.jstl.core.LoopTagSupport
-
- org.apache.taglibs.standard.tag.common.core.ForEachSupport
-
- All Implemented Interfaces:
java.io.Serializable
,LoopTag
,javax.servlet.jsp.tagext.IterationTag
,javax.servlet.jsp.tagext.JspTag
,javax.servlet.jsp.tagext.Tag
,javax.servlet.jsp.tagext.TryCatchFinally
- Direct Known Subclasses:
ForEachTag
,ForEachTag
,ForEachTag
public abstract class ForEachSupport extends LoopTagSupport
Support for tag handlers for <forEach>, the core iteration tag in JSTL 1.0. This class extends LoopTagSupport and provides ForEach-specific functionality. The rtexprvalue library and the expression-evaluating library each have handlers that extend this class.
Localized here is the logic for handling the veritable smorgasbord of types supported by <forEach>, including arrays, Collections, and others. To see how the actual iteration is controlled, review the javax.servlet.jsp.jstl.core.LoopTagSupport class instead.
- See Also:
LoopTagSupport
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ForEachSupport.ArrayIterator
Iterator over an array, including arrays of primitive types.private static class
ForEachSupport.DeferredIterator
private static class
ForEachSupport.EnumerationIterator
Iterator over an Enumeration.private static class
ForEachSupport.IndexedDeferredIterator
private static class
ForEachSupport.IteratedDeferredIterator
private static class
ForEachSupport.ReadOnlyIterator
private static class
ForEachSupport.ToEndIterator
Iterator that simply counts up to 'end.' Unlike the previous implementation this does not attempt to pre-allocate an array containing all values from 0 to 'end' as that can result in excessive memory allocation for large values of 'end.' LoopTagSupport calls next() 'begin' times in order to discard the initial values, In order to maintain this contract, this implementation always starts at 0.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Iterator
items
protected java.lang.Object
rawItems
-
Fields inherited from class javax.servlet.jsp.jstl.core.LoopTagSupport
begin, beginSpecified, deferredExpression, end, endSpecified, itemId, statusId, step, stepSpecified
-
-
Constructor Summary
Constructors Constructor Description ForEachSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
hasNext()
Returns information concerning the availability of more items over which to iterate.private boolean
isIndexed(java.lang.Object o)
protected java.lang.Object
next()
Returns the next object over which the tag should iterate.protected void
prepare()
Prepares for a single tag invocation.void
release()
Releases any resources this LoopTagSupport may have (or inherit).private java.util.Iterator
toIterator(java.lang.Object rawItems)
-
Methods inherited from class javax.servlet.jsp.jstl.core.LoopTagSupport
doAfterBody, doCatch, doFinally, doStartTag, getCurrent, getDelims, getLoopStatus, setVar, setVarStatus, validateBegin, validateEnd, validateStep
-
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
-
-
-
-
Method Detail
-
prepare
protected void prepare() throws javax.servlet.jsp.JspTagException
Description copied from class:LoopTagSupport
Prepares for a single tag invocation. Specifically, allows subclasses to prepare for calls to hasNext() and next(). Subclasses can assume that prepare() will be called once for each invocation of doStartTag() in the superclass.
- Specified by:
prepare
in classLoopTagSupport
- Throws:
javax.servlet.jsp.JspTagException
-
toIterator
private java.util.Iterator toIterator(java.lang.Object rawItems) throws javax.servlet.jsp.JspTagException
- Throws:
javax.servlet.jsp.JspTagException
-
isIndexed
private boolean isIndexed(java.lang.Object o)
-
hasNext
protected boolean hasNext() throws javax.servlet.jsp.JspTagException
Description copied from class:LoopTagSupport
Returns information concerning the availability of more items over which to iterate. This method must be provided by concrete subclasses of LoopTagSupport to assist the iterative logic provided by the supporting base class.
See next for more information about the purpose and expectations behind this tag.
- Specified by:
hasNext
in classLoopTagSupport
- Returns:
- true if there is at least one more item to iterate over, false otherwise
- Throws:
javax.servlet.jsp.JspTagException
- See Also:
LoopTagSupport.next()
-
next
protected java.lang.Object next() throws javax.servlet.jsp.JspTagException
Description copied from class:LoopTagSupport
Returns the next object over which the tag should iterate. This method must be provided by concrete subclasses of LoopTagSupport to inform the base logic about what objects it should iterate over.
It is expected that this method will generally be backed by an Iterator, but this will not always be the case. In particular, if retrieving the next object raises the possibility of an exception being thrown, this method allows that exception to propagate back to the JSP container as a JspTagException; a standalone Iterator would not be able to do this. (This explains why LoopTagSupport does not simply call for an Iterator from its subtags.)
- Specified by:
next
in classLoopTagSupport
- Returns:
- the java.lang.Object to use in the next round of iteration
- Throws:
javax.servlet.jsp.JspTagException
- for other, unexpected exceptions
-
release
public void release()
Description copied from class:LoopTagSupport
Releases any resources this LoopTagSupport may have (or inherit).- Specified by:
release
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
release
in classLoopTagSupport
-
-