Generalized iterating tags Listing 10.4 Source code for
Generalized iterating tags Listing 10.4 Source code for the generic iteration interface package book.iteration; import javax.servlet.jsp.JspException; public interface IterationSupport { public boolean hasNext() throws JspException; public Object getNext() throws JspException; } Why do we need another iteration/enumeration interface, as Java already offers plenty. You may also wonder, why a JspException is thrown from the methods hasNext() and getNext(). Shouldn t a generic interface remove JSP related ties? We do this because we want to provide better JSP integration. Let s explore our motivation for this integration. NOTE We could consider the option of defining a new exception type (such as IterationException) that the iteration support methods could throw; but why should we? This code is written for the JSP tags, and we are not going to reuse it. In 99 percent of all cases, you are going to throw a JspException as a result of the error. Based on this argument, we ve rejected the new exception type idea, and continue to use JspException as our error-reporting vehicle. 10.2.2 IterationTagSupport Let s look at the basic iteration tag class, IterationTagSupport, and how it uses IterationSupport. Before taking a look into the implementation of Iteration- TagSupport as presented in listing 10.5, let s consider how we would like it to work. What should IterationTagSupport do? Most emphatically, the generic iteration tag class should automatically take care of iteration-related issues such as flow control, as well as exporting default iterator variables. In addition, it must be able to: Create an IterationSupport object out of the elements provided as a tag attribute. This can be accomplished by defining a method that our specialized iteration tags can override and that IterationTagSupport will call during its doStartTag(). By specialized tag we mean the special version of the tag that
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services