Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Put JSF to work

Build a real-world Web application with JavaServer Faces, the Spring Framework, and Hibernate

  • Print
  • Feedback

Page 2 of 6

  • Each product has a unique product ID
  • Each product belongs to at least one category
  • The product ID cannot change once created


Assumptions

We make the following assumptions for the application's design and implementation:

  • English is the default language; no internationalization is required
  • No more than 500 products exist in the catalog
  • The catalog is not updated frequently


Page flow

Figure 2 shows all of JCatalog's pages and the transitions among them.

Figure 2. Page-flow diagram. Click on thumbnail to view full-size image.

The application has two groups of pages: public Internet and administration intranet. The intranet is accessible only to the users who log in the system successfully. ProductSummary is not presented to the users as a separate page. It displays in an HTML frame within the Catalog page. ProductList is a special catalog viewable only by the administrators. It contains links for creating, editing, and deleting products.

Figure 3 is a mock-up of the Catalog page. Ideally, for each page, a mock-up that details information for all the controls and the content required on the page should be included in the requirements documentation.

Figure 3. Mock-up of the Catalog page. Click on thumbnail to view full-size image.

High-level architecture design

The next phase in designing a Web application is the high-level architecture design. It involves subdividing the application into functional components and partitioning these components into tiers. The high-level architecture design is neutral to the technologies used.

Multitiered architecture

A multitiered architecture partitions the whole system into distinct functional units—client, presentation, business-logic, integration, and enterprise information system (EIS). This ensures a clean division of responsibility and makes the system more maintainable and extensible. Systems with three or more tiers prove more scalable and flexible than a client-server system, in which no business-logic middle tier exists.

The client tier is where the data model is consumed and presented. For a Web application, the client tier is normally the Web browser. The browser-based thin client does not contain presentation logic; it relies on the presentation tier.

The presentation tier exposes the business-logic tier services to the users. It knows how to process a client request, how to interact with the business-logic tier, and how to select the next view to display.

The business-logic tier contains an application's business objects and business services. It receives requests from the presentation tier, processes the business logic based on the requests, and mediates access to the EIS tier's resources. Business-logic tier components benefit most from system-level services such as security management, transaction management, and resource management.

The integration tier is the bridge between the business-logic tier and the EIS tier. It encapsulates the logic to interact with the EIS tier. Sometimes, the combination of the integration tier and the business-logic tier is referred to as the middle tier.

Application data persists in the EIS tier. It contains relational databases, object-oriented databases, and legacy systems.

JCatalog's architecture design

Figure 4 shows JCatalog's high-level architecture design and how it fits into the multitiered architecture.

Figure 4. High-level architecture diagram. Click on thumbnail to view full-size image.

The application uses a multitiered nondistributed architecture. Figure 4 shows us the partitioning of the application tiers and the technologies chosen for each tier. It also serves as the sample application's deployment diagram. For a collocated architecture, the presentation, business-logic, and integration tiers are physically located in the same Web container. Well-defined interfaces isolate each tier's responsibility. The collocated architecture makes the application simple and scalable.

For the presentation tier, experience shows that the best practice is to choose an existing, proven Web application framework rather than designing and building a custom framework. We have several Web application frameworks to choose from, e.g., Struts, WebWork, and JSF. We use JSF for JCatalog.

Either EJB (Enterprise JavaBeans) or POJO (plain old Java objects) can be used to build the business-logic tier. EJB with remote interfaces is a better choice if the application is distributed. Since JCatalog is a typical Web application with no remote access required, POJO, with the help of the Spring Framework, is used to implement the business-logic tier.

The integration tier handles the data persistence with the relational database. Different approaches can be used to implement the integration tier:

  • Pure JDBC (Java Database Connectivity): This is the most flexible approach; however, low-level JDBC is cumbersome to work with, and bad JDBC code does not perform well.
  • Entity beans: An entity bean with container-managed persistence (CMP) is an expensive way to isolate data-access code and handle O/R (object-relational) mapping data persistence. It is an application-server-centric approach. An entity bean does not tie the application to a particular type of database, but does tie the application to the EJB container.
  • O/R mapping framework: An O/R mapping framework takes an object-centric approach to implementing data persistence. An object-centric application is easy to develop and highly portable. Several frameworks exist under this domain—JDO (Java Data Objects), Hibernate, TopLink, and CocoBase are a few examples. We use Hibernate in the sample application.


Now let's discuss the design issues associated with each application tier. Since JSF is a relatively new technology, I emphasize its use.

Presentation tier and JavaServer Faces

The presentation tier collects user input, presents data, controls page navigation, and delegates user input to the business-logic tier. The presentation tier can also validate user input and maintain the application's session state. In the following sections, I discuss the presentation tier's design considerations and patterns, and the reason I chose JSF to implement JCatalog's presentation tier.

  • Print
  • Feedback

Resources