Sei sulla pagina 1di 22

2

Designing Java EE Applications

Copyright © 2007, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do


the following:
• Identify Java EE design patterns and their purpose
• Describe the Model-View-Controller (MVC)
architecture
• Define the purpose and role of Struts
• Define the purpose and role of JavaServer Faces
(JSF)
• Define the Oracle Application Development
Framework

2-2 Copyright © 2007, Oracle. All rights reserved.


Realizing Benefits of Java EE

To leverage the full benefits of Java EE, you must


design applications that are:
• Portable: You should be able to redeploy the Java
EE applications to different servers, databases,
and so on.
• Scalable: Web applications should be able to
handle large numbers of users.
• Maintainable: A minimum amount of coding
should be necessary for a new business rule.
• Reusable: For example, a class that processes
credit cards should be reused by multiple
applications.
• Simple: The business need should be solved with
the least amount of complexity.

2-3 Copyright © 2007, Oracle. All rights reserved.


Java EE Issues

It is important to follow certain guidelines for the


design and development of any new technology:
• Implement generally accepted design patterns and
architectures.
• Focus on real business needs rather than simply
adopting new technology.
• Employ the simplest technology to solve a
business problem.

2-4 Copyright © 2007, Oracle. All rights reserved.


Java EE Design Patterns

Recurring application development issues have led to


the acceptance of design patterns. The generally
accepted design patterns include (but are not limited
to) the following:
• Presentation-tier patterns
– Intercepting filter
– Controller servlet (as used in MVC)
• Business-tier patterns
– Data Access Object
– Data Transfer Object

2-5 Copyright © 2007, Oracle. All rights reserved.


The MVC Design Pattern

MVC is a framework that separately identifies the


components of an application as:
• Business functionality (Model)
• Presentation (View)
• Control logic (Controller)

View Controller

Model

2-6 Copyright © 2007, Oracle. All rights reserved.


The Model

• The model represents the enterprise data and


business rules that handle access and updates.
• You can simplify the model by using two
mechanisms called “facade class” and “command
pattern.”
– A facade encapsulates, hides the complexity of, and
coordinates the operations between cooperating
classes.
– A command pattern encapsulates each application
function in a separate class.
• The model is often implemented using EJBs.

2-7 Copyright © 2007, Oracle. All rights reserved.


The View

• The view focuses on presentation and is


responsible for maintaining consistency between
data presentation and model changes. It enables:
– Presentation to be changed without altering
programming logic
– Development by Web page authors having only
visual design skills
• The view is commonly implemented using JSPs.

2-8 Copyright © 2007, Oracle. All rights reserved.


The Controller

• The controller provides interaction with the client,


serving as a “glue” between the model and the
view.
• The controller:
– Interprets user requests and controls business
objects to fulfill these requests
– Removes navigation coding from the view
– Can be implemented in the client, Web, or EJB tier,
or in a combination of these tiers
• The controller is usually implemented as a servlet.
• Struts and JSF are two widely used
implementations.

2-9 Copyright © 2007, Oracle. All rights reserved.


MVC in Oracle Application Server 10g
Containers for Java EE (OC4J)

Event Event is passed


to the Controller

Controller changes
Controller Model or View

View gets data


View View from Model

Model updates View


Model when data changes

2-10 Copyright © 2007, Oracle. All rights reserved.


Struts: Overview

Struts is a framework for implementing the MVC


design pattern in Java EE applications.
Struts:
• Is an open-source project from the Apache
Software Foundation
• Is implemented by an XML-driven controller
servlet
• Uses standard Java EE Web technologies—
servlets, JSPs, and tag libraries
• Can be used with other view-layer technologies:
– Tiles: Page layout mechanism using JSP templates
– Velocity: Page templating

2-11 Copyright © 2007, Oracle. All rights reserved.


Struts Components

• Action Servlet: Part of the controller that receives


user inputs, and state changes and issues view
selections
• Action: Part of the controller that interacts with the
model to execute a state change or query
• Form Beans: Data (from forms) bundled into
JavaBeans for reuse and validation
• Action Forward: Stores the path to a page where
the user is sent
• Action Mapping: Tells the servlet how each
request URI is mapped to an Action
• Struts-config.xml: Contains the definitions of
the Struts components used in an application
2-12 Copyright © 2007, Oracle. All rights reserved.
Struts Page Flow Design

Use the Struts Page Flow Diagram to create the


top-level page flow design of a Struts application:

2-13 Copyright © 2007, Oracle. All rights reserved.


2-14 Copyright © 2007, Oracle. All rights reserved.
JSF: Overview

JavaServer Faces (JSF) provides the same benefits as


the Struts architecture, including:
• Controller servlet (MVC implementation)
• Declarative and visual design in JDeveloper
• XML configuration file (faces-config.xml)

2-15 Copyright © 2007, Oracle. All rights reserved.


Oracle Application Development
Framework (ADF)

• End-to-end Java EE framework


• Utilizes and adds value to the Java EE platform
• Enables developers to focus on the application,
not the configuration
• Creates reusable and maintainable code
• Implements Java EE best practices and design
patterns, including MVC

2-16 Copyright © 2007, Oracle. All rights reserved.


Oracle ADF Implementation

• Model
– ADF Business Components
– TopLink Java Objects
– EJBs
– Web services
• Controller
– Struts or JSF
• View
– JSPs, JSF pages, or ADF Swing

2-17 Copyright © 2007, Oracle. All rights reserved.


Oracle WebCenter Suite

• Is an integrated technology suite comprising:


– JavaServer Faces
– Portal
– Web 2.0 services
• Provides the ability to build applications that
enable users to interact directly with services such
as:
– Instant messaging
– Voice over IP
– Discussion forums
– Wiki services

2-18 Copyright © 2007, Oracle. All rights reserved.


2-19 Copyright © 2007, Oracle. All rights reserved.
Summary

In this lesson, you should have learned how to:


• Identify Java EE design patterns and their purpose
• Describe the Model-View-Controller (MVC)
architecture
• Define the role of Struts in an MVC framework
• Define the role of JSF in an MVC framework
• Describe how Oracle Application Development
Framework implements Java EE’s best practices

2-20 Copyright © 2007, Oracle. All rights reserved.


Practice Overview:
Identifying MVC components

This practice covers the following topics:


• Running the course application
• Creating an application with two projects
• Creating a database connection to access the
SRDEMO schema

2-21 Copyright © 2007, Oracle. All rights reserved.


2-22 Copyright © 2007, Oracle. All rights reserved.

Potrebbero piacerti anche