Skip to content

Package: IterationTag

IterationTag

Coverage

1: /*
2: * Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp.tagext;
20:
21: import jakarta.servlet.jsp.JspException;
22:
23: /**
24: * The IterationTag interface extends Tag by defining one additional method that controls the reevaluation of its body.
25: *
26: * <p>
27: * A tag handler that implements IterationTag is treated as one that implements Tag regarding the doStartTag() and
28: * doEndTag() methods. IterationTag provides a new method: <code>doAfterBody()</code>.
29: *
30: * <p>
31: * The doAfterBody() method is invoked after every body evaluation to control whether the body will be reevaluated or
32: * not. If doAfterBody() returns IterationTag.EVAL_BODY_AGAIN, then the body will be reevaluated. If doAfterBody()
33: * returns Tag.SKIP_BODY, then the body will be skipped and doEndTag() will be evaluated instead.
34: *
35: * <p>
36: * <B>Properties</B> There are no new properties in addition to those in Tag.
37: *
38: * <p>
39: * <B>Methods</B> There is one new methods: doAfterBody().
40: *
41: * <p>
42: * <B>Lifecycle</B>
43: *
44: * <p>
45: * Lifecycle details are described by the transition diagram below. Exceptions that are thrown during the computation of
46: * doStartTag(), BODY and doAfterBody() interrupt the execution sequence and are propagated up the stack, unless the tag
47: * handler implements the TryCatchFinally interface; see that interface for details.
48: *
49: * <p>
50: * <IMG src="doc-files/IterationTagProtocol.gif" alt="Lifecycle Details Transition Diagram for IterationTag">
51: *
52: * <p>
53: * <B>Empty and Non-Empty Action</B>
54: * <p>
55: * If the TagLibraryDescriptor file indicates that the action must always have an empty element body, by a
56: * <body-content> entry of "empty", then the doStartTag() method must return SKIP_BODY.
57: *
58: * <p>
59: * Note that which methods are invoked after the doStartTag() depends on both the return value and on if the custom
60: * action element is empty or not in the JSP page, not on how it's declared in the TLD.
61: *
62: * <p>
63: * If SKIP_BODY is returned the body is not evaluated, and then doEndTag() is invoked.
64: *
65: * <p>
66: * If EVAL_BODY_INCLUDE is returned, and the custom action element is not empty, the body is evaluated and "passed
67: * through" to the current out, then doAfterBody() is invoked and, after zero or more iterations, doEndTag() is invoked.
68: */
69: public interface IterationTag extends Tag {
70:
71: /**
72: * Request the reevaluation of some body. Returned from doAfterBody.
73: *
74: * For compatibility with JSP 1.1, the value is carefully selected to be the same as the, now deprecated,
75: * BodyTag.EVAL_BODY_TAG,
76: *
77: */
78: public final static int EVAL_BODY_AGAIN = 2;
79:
80: /**
81: * Process body (re)evaluation. This method is invoked by the JSP Page implementation object after every evaluation
82: * of the body into the BodyEvaluation object. The method is not invoked if there is no body evaluation.
83: *
84: * <p>
85: * If doAfterBody returns EVAL_BODY_AGAIN, a new evaluation of the body will happen (followed by another invocation
86: * of doAfterBody). If doAfterBody returns SKIP_BODY, no more body evaluations will occur, and the doEndTag method
87: * will be invoked.
88: *
89: * <p>
90: * If this tag handler implements BodyTag and doAfterBody returns SKIP_BODY, the value of out will be restored using
91: * the popBody method in pageContext prior to invoking doEndTag.
92: *
93: * <p>
94: * The method re-invocations may be lead to different actions because there might have been some changes to shared
95: * state, or because of external computation.
96: *
97: * <p>
98: * The JSP container will resynchronize the values of any AT_BEGIN and NESTED variables (defined by the associated
99: * TagExtraInfo or TLD) after the invocation of doAfterBody().
100: *
101: * @return whether additional evaluations of the body are desired
102: * @throws JspException if an error occurred while processing this tag
103: */
104: int doAfterBody() throws JspException;
105: }