Sie sind auf Seite 1von 26

Programming Applications

Spring 2015-2016
Ass. Prof. Dr. Pelin GRGEL
(paras@istanbul.edu.tr)
09.03.2016

15:10

MVC (Model-View-Controller)

MVC which is an essential architectural


pattern in software was firstly defined in
1979.
It divides the application into three
components:
Model
View
Controller
MVC design defines the interactions
between them.

15:10

MVC (Continued)

This architecture is a significant


cornerstone for many applications due to
its benefits and advantages and accepted
by most of the coders and software
engineers.
Even if you are junior developer you
probably faced with a problem called
Complexity of Project. MVC helps you to
decrease complexity of project.
In the creation process of a complex web
application it is convenient to divide it into
particular functional components to
preserve the good arrangement of source
codes.

15:10

MVC (Continued)

It enables not only to separate the


application appearance from data
and its code, but also to divide
various types of application
functional components and their
classification into a well-arranged
architecture.
The aim of MVC is to develop the
layers of the project seperately. This
helps the project to extent, the
codes to be updated and the test to
be performed easily.

15:10

MVC

15:10

MVC - Model

In an application, model represents


data and the rules for accessing it.
It handles data processing and
database.
Model processes events sent by
Controller. After processing these
events then it sends processed data
to Controller or directly to the View
side.

15:10

MVC - Controller

Controller is like brain of the system. It


processes every request, prepares other
parts of the system like Model and View.
Then the system determines what to do
by controllers commands.
It translates the user's interactions with
the View into actions that the Model will
perform.
In a MVC application, View just displays
the information, Controller manages user
inputs and interactions.

MVC View

View prepares an interface to show to the


user. Controller or Model tells View what
to show to the user.
Handles requests from user and informs
controller.
Specifies exactly how the Model data
should be presented.
A View requests the information from the
Model that it needs to generate an output
representation.

15:10

Dependency Hierarchy

There is usually a kind of hierarchy in the


MVC pattern. The Model knows only about
itself.
The View however, knows about the
Model. But the View knows nothing about
the Controller.
The Controller knows about both the
Model and the View.

15:10

Dependency Hierarchy
(Continued)

For example If you click on a button


while playing a game, the Controller
knows which function will be called in
the Model.
If you press the button for switching
between first and second player, the
Controller knows which function will
be called in the View to request the
display change.

15:10

10

Dependency Hierarchy
(Continued)

The hierarchy minimizes


dependencies. No matter how the
View class is modified, the Model will
still work.
Even if the system is moved from
Windows to an app in a smart phone,
the Model can be moved with no
changes. But the View and Controller
probably need to be updated.

15:10

11

MVC

15:10

12

Java Server Faces


Some Differences Between JSP and JSF

JSF is a framework for web


applications.
JSF uses the MVC architecture.
In JSP, all Java codes are embedded
into the HTML codes.
JSF is faster and for more complex
applications.

15:10

13

Process of a JSF Execution


1.

2.

3.
4.

15:10

You invoke the application from a


server
Browser requests the app.s JSF
page
Web server receives this request
GlassFish application server or any
JSF 2.0 compliant container such as
Apache TomCat behaves like a web
server.

14

Process of a JSF Execution


(Continued)
5.

6.

15:10

The framework includes Faces


servlet (a software component
running on the server) that
processes each requested page.
The framework returns a response
to the client.

15

Setup GlassFish Server

Go;

https://glassfish.java.net/download.html
Choose;
Java EE 7 Full Platform
Download;
glassfish-4.1.1.zip
Extract the zip file (keeping the name of
the file) under C:\ driver.
15:10

Start GlassFish Server

Go to the GlassFish folder under C


driver. Copy the path of the bin file.
Click the Start button
In the Search box, type cmd
Paste this path after cd command
Write the start command of the
GlassFish server:

15:10

C:\glassfish4\bin\>asadmin start-domain

15:10

15:10

JSF Components

15:10

JSF App -1 (Buttons)


index.xhtml

15:10

JSF App -1 (Buttons)


index.xhtml

15:10

JSF App -1 (Buttons)


login.xhtml

15:10

JSF App -1 (Buttons)


UserBean.java

15:10

JSF App. 2

index.xhtml (JSF file)

15:10

JSF App. 2

WebTimeBean.java (Bean file)

15:10

Das könnte Ihnen auch gefallen