Generalized iterating tags // User probably disconnected …

CHAPTER 10 Iterating with tags D Override if you have additional attributes in the specialized tag (you probably do). E Override if you have additional service state in the specialized tag. Listing 10.5 shows that the general structure of IterationTagSupport is very similar to the one presented in SimpleForeachTag. The tag is merely a generic iteration infrastructure with several methods to override as explaned in the annotations. Note also that IterationTagSupport extends our now familiar ExBodyTagSupport, and therefore inherits its functionality. An improved ForeachTag which uses IterationTagSupport We ve mentioned several times the concept of a specialized tag, by which we infer a tag that uses our generic interface and class for a specific iterator and object type. Let s now look at one such specialized tag, ForeachTag, which uses IterationTag- Support to support an Iterator containing a list of Strings (see listing 10.6). Listing 10.6 Source code for the ForeachTag handler class package book.iteration; import java.util.StringTokenizer; import java.util.LinkedList; import java.util.Iterator; import java.util.List; import book.util.LocalStrings; import book.util.ExBodyTagSupport; import javax.servlet.jsp.JspException; public class ForeachTag extends IterationTagSupport { static LocalStrings ls = LocalStrings.getLocalStrings(ForeachTag.class); protected String elements = null; public void setElements(String elements) { this.elements = elements; } protected void fetchIterationSupport() throws JspException { List l = new LinkedList(); b StringTokenizer st = new StringTokenizer(elements, “,”); while(st.hasMoreTokens()) { l.add(st.nextToken()); } elementsList = new IteratorIterationSupport(l.iterator()); }

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

Bookmark the permalink.

Comments are closed.