The IterationTag Interface in JSP

By: Henry Emailed: 1757 times Printed: 2444 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.

 IterationTag.java

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

Comments(0)


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: `java.net.BindException: 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 Alert Example
JSP Program for display Date
Comparison operators in JSP
JSP CheckBox Example
Sending Email using JSP
Disabling Scriptlets in JSP using web.xml
Uploading an Image to a Database using JSP
Embedding java codes in jsp sciptlets
Arithmetic Evaluation Using the Expression Language in JSP
Enable/Disable Scripting Elements in JSP
Retrieving a Portion of a String
JSP Example to connect to MS SQL database using Tomcat Connection Pool
Writing your first JSP page
Most Emailed Articles (in JSP)
Embedding java codes in jsp sciptlets
The taglib, tag, include, attribute and the variable Directive in JSP
What is JSP?
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Scriptlets
Server Side Programming
Syntax For JSP Declaratives
Tags using in jsp
JSP pages in servlet
Combining Scriptlets with HTML
JSP Directives
Form processing in JSP
Declaring variable in JSP