Iterating with tags 101 To further illustrate how
CHAPTER 10 Iterating with tags
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