JSP Tag Libraries

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


new EnumerationIterationSupport((Enumeration)o); } else if(o.getClass().isArray()) {


elementsList = new ArrayIterationSupport(o);


} else {


// Throw an exception to inform that we cannot // iterate this object


}


}


// The reflection code below this line // was removed from this listing


}

B getPointed() retrieves the object the tag should iterate on. This method is inherited from ExBodyTagSupport.
© Gets the referenced object and wraps it within the appropriate iterationSupport implementation.


Iterating with tags


Apart from the reflection related code which we’ve omitted (we’ve seen how this code works in chapter
8), iterateTag’s implementation consists of a single method implementation: fetchiterationSupport(). This method merely checks the object that is passed as the tag attribute and selects an appropriate iterator and iterationSupport wrapper, based on the object’s type.

IterateTagExtraInfo


Accompanying the iterateTag is the IterateTagExtraInfo whose implementation is fairly effortless. Once again, we need to create this TagExtrainfo object for our iterateTag because we will be exporting a scripting variable from it. From an attribute and variable exportation point of view, iterateTag and ExportTag (as presented in chapter 8) are quite similar. The only difference is that our current variable is exported as a nested variable, meaning its scope only exists within the tag’s body. Because they are so similar, all we need to do is inherit ExportTagExtrainfo (again, from chapter 8) and modify the Variabieinfo it returns to reflect a nested variable. As listing 10.10 shows, this is exactly what we did.


Listing 10.10 Source code for the IterateTagExtraInfo class

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