JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


class IteratorIterationSupport implements IterationSupport { О Iterator i = null;


IteratorIterationSupport(Iterator i)


{


this.i = i;


}


public boolean hasNext() throws JspException


{


return i.hasNext();


}


public Object getNext() throws JspException


{


return i.next();


}


}


Parsing the list specification string and making an IterationSupport out of it. Clearing the additional tag property.


Implementing an IterationSupport class that uses a Java Iterator object.


О


©


D


The new ForeachTag has most of its code implementing its tag-specific functionality, that is, dealing with an Iterator of Strings. Also of note in our implementation is the additional IteratorIterationSupport class we created, which is simply an implementation of the generic IterationSupport that works on the java.util.Iterator interface. We can imagine a similar class that works on Arrays and even another for Enumerations (or perhaps one that handles all?). The IteratorIterationSupport class is not, of course, unique to ForeachTag and we will be able to reuse it many times in other specialized tags.


We now have a way to easily create iteration tags that iterate on all sorts of objects. We’ll flex the power of this infrastructure in the next section in creating a tag that is capable of iterating on just about anything.


Iterating with tags

10.3 IterateTag


The previous section presented a generic iteration tag infrastructure that we will now use to develop a new iteration tag (named IterateTag) which will be able to iterate over the following types of objects:

Скачать в pdf «JSP Tag Libraries»