The IterationTag Interface in JSP

By: Henry Emailed: 1786 times Printed: 2614 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The IterationTag interface was introduced as a part of the JSP 1.2 specification in an attempt to simplify the procedure for evaluating and reevaluating body content multiple times. This was previously possible with the JSP 1.1 BodyTag interface, although the implementation details were complex.

package javax.servlet.jsp.tagext;
import javax.servlet.jsp.JspException;
public interface IterationTag extends Tag {
public final static int EVAL_BODY_AGAIN = 2;
int doAfterBody() throws JspException;

The interface itself is fairly small, and this is because it extends the Tag interface. Effectively, a single method has been added to the tag life cycle called doAfterBody(), and it’s this method that provides you with the ability to ask that a tag’s body content is evaluated more than once. Let’s see how this affects the tag life cycle.

The Iteration Tag Life Cycle
Figure below illustrates the iteration tag life cycle and shows where the new doAfterBody() method fits in with the life cycle of a custom tag.

To support iteration, the doAfterBody() method is called after doStartTag(). The return value of doAfterBody() indicates whether the tag body is evaluated again or processing continues to the doEndTag() method.

Setting the Context

The first thing that happens is that the contextual information (the PageContext and parent Tag) is passed to the tag handler instance.

The Start Tag

After the context has been set, the doStartTag() method is called and one of two things can happen. First, the doStartTag() method can return SKIP_BODY, meaning that the body content is ignored and processing proceeds to the doEndTag() method as before. Alternatively, a value of EVAL_BODY_INCLUDE can be returned from the doStartTag() method, signaling to the JSP container that the body content should be evaluated and included in the page. Again, this is the same as with the Tag interface, although it’s after the body content has been evaluated that things start to change.

After the Body

After the body content has been evaluated, the new doAfterBody() method is called, the primary purpose of which is to determine whether the body content should be reevaluated. If this is the case, the method should return the EVAL_BODY_AGAIN constant defined within the IterationTag interface. On the other hand, and when no more evaluations of the body content should happen, the SKIP_BODY value should be returned.

The End Tag

Finally, regardless of whether or not the body was evaluated and reevaluated multiple times, the doEndTag() method is called in the same way as the other tags that you’ve seen in this chapter. Again, possible return values are EVAL_PAGE and SKIP_PAGE.

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Henry
Generating Your Key Pair example using keytool in Java
Summary of Operators in Java
JDBC Basics and JDBC Components
The IterationTag Interface in JSP
Trigonometric, Hyperbolic, Exponential and Logarithmic Functions in C
Using Bit-field in C
Java Beans and the Expression Language
Initialization of Variables in C
Creating Struts Modules
else if statement in C
Line Counting sample program in C
Accessing Context Data in Beans using JSF
Using peek() and putback() with cin in C++
Internationalization Support in J2ME MIDP
java.lang.SecurityException: MIDP lifecycle does not support system exit.

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
JSP Alert Example
Comparison operators in JSP
Sending Email using JSP
Uploading an Image to a Database using JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Advantages of JSP
Writing your first JSP page
Uploading a file to a server using JSP
The Request Object in JSP
Disabling Scriptlets in JSP using web.xml
Deploying an Individual JSP on Tomcat
Automatically Refreshing a JSP
Most Emailed Articles (in JSP)
The Tag Life Cycle with Attributes in JSP
Calling JSP from a batch file
JSP Program for display Date
Sessions in JSP
Simple HTML-Building Utilities
Handling Events
Using a DataSource from WebLogic in a JSP
The JSP Program running first Time.
Declaring variable in JSP
The Advantages of JSP
Password Object
Retrieving a Portion of a String
Automatically Including Preludes and Codas in JSP
The Differences Between Simple and Classic Tags in JSP