JSP Tag Libraries

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




public String getType() {

return type;



protected void exportVariables() throws JspException {


current = elementsList.getNext();

ClassLoader classLoader=




EJBObj ect obj ect =

(EJBObject)javax.rmi.PortableRemoteObject.narrow( current,Class.forName(getType(), true, classLoader)); pageContext.setAttribute(id, object); }catch(ClassNotFoundException cnfe){

throw new JspException(cnfe.getMessage());


о Overriding setType() to save the type The tag overrides setType() of the Iter-ateTag class and adds a method for reading this value. We will need the type’s value in order to narrow the iterator object into a concrete type in exportVariables().

© Retrieves the page’s ClassLoader D Narrows the next remote interface to the specified class type The tag overrides exportVariables() of the IterationTag-Support class. In that method, the tag first retrieves the current page’s ClassLoader. The tag then narrows the next item in the collection into the remote interface type specified by the user. Finally, we add the remote interface to the page scope.

As the new tag can use the same TEI as the original <iterate>, we needn’t create a TEI for this tag.

The IterateEJBTag TLD

We now need to update the EJB TLD by adding the tag descriptor as in listing 12.27.

Custom tags and J2EE

Listing 12.27 Adding the tag to the descriptor



<tagclass>book.j2ee.IterateEJBTag</tagclass> <teiclass>book.iteration.IterateTagExtraInfo</teiclass> <bodycontent>JSP</bodycontent>


Iterate over an Object. The object can be an array, an Iterator or an Enumeration of Remote interfaces.


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