The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

The Example Tags

This chapter describes the tasks involved in using and defining tags. The chapter illustrates the tasks with excerpts from the JSP version of the Duke's Bookstore application discussed in JavaServer PagesTM Technology rewritten to take advantage of two tag libraries: Struts and tutorial-template. The source for the application is located in examples/src/web/bookstore3.

The Struts tag library provides a framework for building internationalized web applications that implement the Model-View-Controller design pattern. Struts includes a comprehensive set of utility custom tags for handling:

The Duke's Bookstore application uses tags from the Struts bean and logic sublibraries.

The tutorial-template tag library defines a set of tags for creating an application template. The template is a JSP page, with place holders for the parts that need to change with each screen. Each of these place holders is referred to as a parameter of the template. For example, a simple template could include a title parameter for the top of the generated screen and a body parameter to refer to a JSP page for the custom content of the screen. The template is created with a set of nested tags-definition, screen, and parameter-that are used to build a table of screen definitions for Duke's Bookstore and an insert tag to insert parameters from the table into the screen.

The third section in the chapter, Examples, describes two tags in detail: the iterate tag from Struts and the set of tags in the tutorial-template tag library.

To build, deploy, and run the example on the J2EE SDK:

  1. Go to examples/src and build the application by executing ant bookstore3 (see How to Build and Run the Examples).
  2. Download and unpack Struts version 1.0 from
    http://jakarta.apache.org/builds/jakarta-struts/
    release/v1.0-b1/ 
    
    Copy struts-bean.tld, struts-logic.tld, and struts.jar from jakarta-struts-1.0-b1/lib to examples/build/web/bookstore3.
  3. Start the Cloudscape database by executing cloudscape -start.
  4. If you have not already created the bookstore database, run ant create-web-db.
  5. Start the j2ee server
  6. Start deploytool
  7. Create a J2EE application called bookstore3.
    1. Select File->New Application or the New Application button.
    2. Enter bookstore3.ear in the Application File Name field.
    3. Click OK.
  8. Add the dispatcher web component and all of the Duke's Bookstore content to the bookstore3 application.
    1. Select File->New Web Component or the Web Component button.
    2. Click the Create New WAR File in Application radio button and select the bookstore3 application from the combo box. Enter bookstore3 in the field labeled WAR Display Name.
    3. Click Add to add the content files. In the Edit Contents dialog, navigate to examples/build/web/bookstore3. Select Dispatcher.class and click Add. Add the JSP pages banner.jsp, bookstore.jsp, bookdetails.jsp, catalog.jsp, showcart.jsp, cashier.jsp, receipt.jsp, initdestroy.jsp, and errorpage.jsp. Add duke.books.gif, struts-bean.tld, struts-logic.tld, tutorial-template.tld, struts.jar and tt.jar. Add the cart, database, and util packages. Click OK.
    4. Click Next.
    5. Select the servlet radio button.
    6. Click Next.
    7. Select Dispatcher from the Servlet class combo box.
    8. Type dispatcher in the Web Component Name field.
    9. Click Next twice.
    10. In the Component Aliases panel click Add and then type /enter in the alias field. Repeat to add the aliases /catalog, /bookdetails, /showcart, /cashier, and /receipt.
    11. Click Finish.
  9. Add the BookDBEJB enterprise bean to the application.
    1. Select File->New Enterprise Bean or the New Enterprise Bean button.
    2. Select bookstore3 from the combo box labeled Enterprise Bean will Go In.
    3. Type BookDBEJB in the JAR Display Name field.
    4. Click Add to add the content files. Navigate to the examples/build/web/ejb directory and add the database and exception packages. Click Next.
    5. Click Next.
    6. Chose Session and Stateless for the Bean Type.
    7. Select BookDBEJBImpl for Enterprise Bean Class.
    8. Select BookDBEJBHome for Home Interface.
    9. Select BookDBEJB for Remote Interface.
    10. Enter BookDBEJB for Enterprise Bean Name.
    11. Enter BookDBEJB in the JNDI Name field next to the BookDB component.
  10. Add a resource reference for the Cloudscape database.
    1. Select the BookDBEJB enterprise bean.
    2. Select the Resource Ref's tab.
    3. Click Add.
    4. Select javax.sql.DataSource from the Type column
    5. Enter jdbc/BookDB in the Coded Name field.
    6. Enter jdbc/Cloudscape in the JNDI Name field.
  11. Add a reference to the enterprise bean BookDBEJB.
    1. Select the bookstore3 WAR.
    2. Select the EJB Ref's tab.
    3. Click Add.
    4. Enter ejb/BookDBEJB in the Coded Name field.
    5. Enter Session in the Type field.
    6. Enter BookDBEJBHome in the Home field.
    7. Enter BookDBEJB in the Remote field.
    8. Enter BookDBEJB in the JNDI Name field.
  12. Add the tag library URI to location mappings (see Declaring Tag Libraries):
    1. Select the bookstore3 WAR.
    2. Select the File Ref's tab
    3. Click the Add button in the JSP Tag Libraries subpanel.
    4. Enter the relative URI /tutorial-template in the Coded Reference field.
    5. Enter the absolute location /WEB-INF/tutorial-template.tld in the Tag Library field.
    6. Repeat for /struts-bean to /WEB-INF/struts-bean.tld and /struts-logic to /WEB-INF/struts-logic.tld.
  13. Deploy the application. Select Tools->Deploy Application or the Deploy Application Button. Click Next twice. Type BookDBEJB in the Application->JNDI Name field and bookstore3 for the context root. Click Next and Finish.
  14. Open the bookstore URL http://<host>:8000/bookstore3/enter.

See Troubleshooting for help with diagnosing common problems.

Home
TOC
PREV TOC NEXT Search
Feedback