JavaServer Page

March 11, 2007

Iterating with tags 101 To further illustrate how

Filed under: JSP Tag Libraries — webmaster @ 6:14 pm

CHAPTER 10 Iterating with tags The selected item is < %= item %>
Executing the above JSP fragment generates the following content: The selected item is 1
The selected item is 2
The selected item is 3
The selected item is 4
Let s look at the code for the SimpleForeachTag s handler (listing 10.1). Listing 10.1 Source code for the SimpleForeachTag handler class package book.iteration; import java.util.StringTokenizer; import java.util.LinkedList; import java.util.List; import java.util.Iterator; import book.util.LocalStrings; import book.util.ExBodyTagSupport; import javax.servlet.jsp.JspException; public class SimpleForeachTag extends ExBodyTagSupport { static LocalStrings ls = LocalStrings.getLocalStrings(SimpleForeachTag.class); Iterator elementsList = null; protected String elements = null; public void setElements(String elements) { this.elements = elements; } public int doStartTag() throws JspException { parseElements(); b if(elementsList.hasNext()) { c return EVAL_BODY_TAG; } return SKIP_BODY; } public void doInitBody() throws JspException { pageContext.setAttribute(id, elementsList.next()); d

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting