JSP Tag Libraries

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

О Defines an instance of CatalogueEntryHome into the JSP scope Walking through the JSP, you’ll see that we add the home interface for the CatalogueEntry EJB to the page scope with an ID of home.

e Uses the home interface to find a CatalogueEntry and to return its remote interface Next, we use the <use> tag to narrow and add the remote interface of CatalogueEntry EJB to the page scope, by asking the home interface to find the CatalogueEntry that has a serial of «ABC123». If such an entry is found, we can refer to «entry» as a scripting variable through the remainder of the JSP, calling methods of the EJB as desired.


In order to iterate through collections of remote interfaces returned by methods called on the EJB home interfaces, we need a tag that works similarly to the <iterate> tag of chapter 10. The only difference will be that this tag will try to narrow the remote interface to the specified type before adding it to the given scope (see listing 12.26). Note that there is an alternative to the updated <iterate> tag. We could use the <use> tag to narrow the iterator exported from the <iterate> tag prior to using it. However this forces the JSP coder to develop insight into the intrinsics of EJB, something we chose to avoid.

Listing 12.26 The implementation of IterateEJBTag

package book.j2ee;

import java.util.Enumeration; import java.util.Iterator; import javax.ejb.*;

import javax.servlet.jsp.JspException; import book.iteration.*;

public class IterateEJBTag extends IterateTag {

protected String type;

public void setType(String type) О

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