JSP Tag Libraries

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

Listing 12.21 Using the EJB home interface

<ejb:home id=»home»



<iter:iterate id=»entry»

type=»book.ejb.catalogue.CatalogueEntry» object=»<%=home.findByType(«pda»).iterator()%>»> <bean:show name=»entry»



In this listing, we let the <iterate> tag iterate over the collection of entries as returned from the finder method, introduce the entries using their remote interface, and display the serial number property for each CatalogueEntry of the type pda. As previously stated, executing this JSP on an application server that uses RMI over IIOP could throw an exception, as the remote interfaces that the <iterate> tag returns to the page have not been narrowed. Later we will solve this by extending the <iterate> tag further. Yet, the narrowing problem is not unique for the <iterate> tag and is going to appear for any remote interface returned by an EJB, so we need a tag that allows us to use the home interface by retrieving and narrowing a remote interface. We’ll now build the UseTag, which will do just that.


Our UseTag is somewhat analogous to the standard JSP <jsp:useBean> tag, but differs in that it lets us use and put into scope an EJB, instead of a standard JavaBean (listing 12.22).

Listing 12.22 The implementation of UseTag

package book.j2ee;

import javax.ejb.*; import javax.naming.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import book.util.ExTagSupport;

public class UseTag extends ExTagSupport {

protected String type; protected EJBObject instance;

public void setType(String type)


this.type = type;


public void setInstance(EJBObject instance)


this.instance = instance;

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