Sunteți pe pagina 1din 28

I am sick and cannot

go to university. Today is
the last date of registering
for a course. How can I
register for the course?

Idea!
I can use the website of
the university to register
for the course.

Wow!
The university website
is very interactive. In addition,
it is lightweight as its
Web pages are downloaded
rapidly.

How can you develop such a Web application?

To develop such a Web application, you need to:


Create a User Interface (UI).
Implement business logic.
Store data in the database.

To create a UI, you need to:


Place UI components on a Web page.

Perform conversions and validations of data entered by the


users in the UI components.

conversion

validation

Format the appearance of UI components.

The font of button


caption is different
from the labels.

Set the layout of Web pages.

Every Web page


has the same
layout.

Customize the UI components.

A set of UI
components are
grouped into a
composite
component.

Refreshes a part of the Web page asynchronously.

Validation is
performed and an
error message is
displayed instantly
without refreshing
the whole Web
page.

So, which technology


should I use to
develop such a Web
application?

You can use JavaServer Faces (JSF) to develop an


interactive and lightweight Web application.
JSF provides:
Inbuilt tags to create interactive user interfaces.
Converters and validators for performing conversions and
validations of user inputs.
Styles to format the appearance of UI components.
Templates to set the layout of Web pages.
Asynchronous JavaScript and XML (AJAX) to refresh a part of
the Web page asynchronously.

Once you have created the UI and converted and


validated user inputs,
what next?

The next step is to implement the business logic that


processes the application data.

Business
Logic

How can you implement the business logic?

I can implement the


business logic by creating
different application
components using the
Java classes.

The application components developed using the Java


classes are tightly coupled.
Consequently, change in one component requires changing
all the dependent components of the application.

Let us consider an example.

Consider the following code snippet:


public class Order{
...........
private Product prod;
private Customer cust;
public Order(){
//Order class is creating its dependent objects
cust = new Customer();
prod = new Product();
}
Dependent
Custom
.............
on
er
}
Orde
r
Dependent
on

Produc
t

If any change is made in the Customer class or the


Product class, the corresponding change needs to be
reflected in the Order class as well.
This requires you to recompile the whole code to reflect the
change in the application.
Changes in
Customer class
or Product class

Result in changes
being made to the
Order class

Dependent
on

Custom
er

Dependent
on

Produc
t

Orde
r

How can I create


loosely-coupled application
components?

You can create loosely-coupled application components by


using the Dependency Injection (DI) feature of the Spring
framework.

Injected
into

Custom
er

Injected
into

Produc
t

Orde
r

Now that you have developed the UI and created


loosely-coupled application components,
what next?

Business
Logic

The next step is to implement the logic to store and retrieve


application data from a database.

Business
Logic

How can you implement the logic to


communicate with a database?

Database

The logic to communicate


with a database can be
implemented by using
a data access technology,
such as JDBC.

The database communication logic implemented by using a


data access technology is database dependent and
requires complex logic implementation in the business tier.
In addition, if the underlying database changes, the entire
code to communicate with the database needs to be
changed.
Communicates
with

Communication
Code for SQL

RDBMS 1

JDBC

May not communicate


with

RDBMS 2

How can I implement the


database communication logic
that is simple and
database independent?

You can implement the database communication logic that


is simple and database independent by using the Hibernate
framework.

Communicates
with

Communication
Code

RDBMS 1

Hiberna
te

Communicates with

RDBMS 2

Therefore, while developing a Web application, you can


use:
JSF for the presentation tier.
Spring for creating loosely-coupled components in the
business tier.
Hibernate for communicating with the database tier.

Presentation
Tier

Business Tier

Database Tier

S-ar putea să vă placă și