JSP Tag Libraries

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


Given these parameters, we have two options for our implementation:


1    Write a set of utility classes (which we could write as standard JavaBeans) and isolate the database code in them.


2    Create an EJB to represent the catalogue entries.


Although the relative simplicity of our application may not warrant EJB use, we’ll try them anyway, for purposes of illustration. To minimize our work, our catalogue entry EJB will use container-managed persistence—the container will be the one responsible for persisting the various catalogue entries to the database, freeing us to concentrate on the details of the application itself and the interfaces that the EJB should support.


Custom tags and J2EE


Let’s now look at each of the interfaces and objects we need to create in building our EJB. Recall from table 12.2 that each EJB will need:


■    A Remote interface that exposes the methods the EJB will support.


■    A Home interface that provides life cycle (creation, finding, etc.) methods for the EJB.


■    An Implementation class that is the guts of the EJB, including any business rules and logic it needs. This would also be the site to place any code for retrieving and setting the EJB’s properties (from/to the database); but since we are using container managed persistence, we don’t have to write this code; the container does it for us.

The remote interface


The first action to take with our new EJB is to define its functionality through its remote interface, which specifies the methods available for its users. If we were writing a plain JavaBean, the public methods of our JavaBean would be the business methods we expose to other Java classes. The methods in an EJB’s remote interface are analogous, in this way, to the public methods in a JavaBean. The operations we want to conduct over the catalogue entries include reading the values stored in the entry and updating them. Supporting these operations yields the remote interface presented in listing 12.1.

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