Chapter 7. Application and system design guidelines 153
Figure 7-5 Command beans
7.2.6 Frameworks
The goal of frameworks is to make it easier to build and maintain Web
applications with reusable components. In addition to providing software
components, a framework will also defined a design or approach.
For instance, when we discussed the MVC pattern, we detailed a wide variety of
possible design alternatives. Without the use of a framework, the project team
would have to carefully chose between the different design approaches, and
them implement all the components using servlets and JSPs.
Using a standard framework, many of the design decisions are already done,
generally following industry best practices. Each framework will define a design
approach in implementing the MVC pattern. The framework will also provide
reusable components which will accelerate and standardize this implementation.
In this section, we examine the following Web application frameworks:
򐂰 JavaServer Faces (JSF) framework
򐂰 The Apache Jakarta Project’s Struts framework
򐂰 IBM’s Enterprise Application Development Frameworks for Java (EAD4J)
HTML
JavaScript
Browser Client
Web Application Server
Command Bean
Model
Page
Construction
View
Controller
Interaction
Controller
Also holds the
result data
Business Logic
External Services
Enterprise
Applications
Enterprise
Data Sources
External
Applications
For example,
Business
Partner
View
Bean
Note: The command bean contains the command execution results, so there
is no need to introduce another result bean. In essence, the command bean
encapsulates both the business logic and result data.
154 Patterns: Implementing Self-Service in an SOA Environment
Although we recommend the use of a framework when implementing the MVC
pattern, there are some issues to consider:
򐂰 Frameworks are restrictive. They are good for what they have been designed
for, but nothing else. Framework choice is critical because customizing a
framework can be difficult.
򐂰 Frameworks impose a way of thinking. Different ideas just do not fit. If the
framework is well-designed, this can be a good thing because it prevents bad
practices.
򐂰 There is a learning curve. It takes time to get started with a framework, partly
because there are more components to deal with and additional configuration
is needed.
JavaServer Faces
The JavaServer Faces is a standard J2EE technology, created by Java
Specification Request (JSR) 127. Although it is still a relatively new concept,
JSFs have wide acceptance by the tool vendors, including the Rational and
WebSphere product line.
The main pieces of a JSF application are:
򐂰 JSF pages
JSPs are built from JSF components, and each component is represented by
a server-side class.
򐂰 Faces servlet
One servlet (
FacesServlet) controls the execution flow.
򐂰 Configuration file
An XML file (
faces-config.xml) that contains the navigation rules between the
JSPs, validators, and managed beans.
򐂰 Tag libraries
The JSF components are implemented in tag libraries.
򐂰 Validators
The Java classes validate the content of JSF components, for example, to
validate user input.
򐂰 Managed beans
Java beans defined in the configuration file hold the data from JSF
components. Managed beans represent the data model and are passed
between business logic and user interface. JSF moves the data between
managed beans and user interface components.
Chapter 7. Application and system design guidelines 155
򐂰 Events
Events are Java code executed in the server for events (for example, a push
button). Event handling is used to pass managed beans to business logic.
Now that we have introduced the JSP components, we examine how they fit in to
the MVC architectural pattern:
򐂰 Model
Managed beans make up the model of a JSF application.
򐂰 View
JSPs make up the view of a JSF Web application. These JSPs are created by
combining model data with predefined (tag libraries) and custom-made UI
components.
򐂰 Controller -
The FacesServlet, which drives navigation and object management, makes
up most of a JSF application’s controller. Event listeners also contribute to the
controller logic.
See Chapter 9, “JSF front-end scenario” on page 239 for a sample
implementation of the MVC pattern using JavaServer Faces. In addition, the
following can provide more information:
򐂰 The official JSF specification
http://java.sun.com/j2ee/javaserverfaces/
򐂰 WebSphere Studio 5.1.2, JavaServer Faces and Service Data Objects,
SG24-6361
Struts
Struts is a Model II servlet-JSP framework offered by the Apache Software
Foundation. Struts supports application architectures based on the Model II
approach, which is an implementation of the traditional MVC paradigm discussed
earlier. Before the emergence of JSF, Struts was the industry standard choice for
implementing the MVC pattern. In fact the JSF specification is heavily influenced
by Struts.
True to the MVC design pattern, Struts applications have three major
components:
򐂰
Controller is implemented using the Struts ActionServlet and classes
extending the Struts Action class
򐂰
View is implemented using JavaServer Pages and Struts form beans
򐂰
Model implements the application's business logic

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.