Vous êtes sur la page 1sur 35

Web Frameworks and

Scripting
Struts, JSF, Ruby on Rails and Ajax

Struts
Struts is popular framework used to develop MVC based web
application.
The framework is designed to streamline the full development
cycle, from building, to deploying and to maintaining applications
over time.

R. LOGAMBIGAI, TA

December 8, 2016

Features of Struts

Configurable MVC components all the components information in


structs.xml file. Need to change any information, simply change it in
the xml file.

POJO based actions - In struts 2, action class is POJO (Plain Old


Java Object) i.e. a simple java class.

Tag support - Struts2 has improved the form tags and the new tags
allow the developers to write less code.

AJAX support - Struts 2 provides support to ajax technology. It is


used to make asynchronous request i.e. it doesn't block the user. It
sends only required field data to the server side not all. So it makes
the performance fast.

Easy Integration - Integration with other frameworks like Spring,


Tiles and SiteMesh is now easier with a variety of integration
available with Struts2.

Theme and Template Support 3 types of theme it supports.:


R. LOGAMBIGAI,
TA
8, 2016
XHTML,
simple
and css_xhtml. Themes and Templates are December
used for
common look and feel.

Struts Components
The Model-View-Controller pattern in Struts is realized with
following five core components:
1. Actions
2. Interceptors
3. Value Stack / OGNL (Object Graph Navigation Language)
4. Results / Result types
5. View technologies

R. LOGAMBIGAI, TA

December 8, 2016

Components of Strut Project


1
Action - Create an action class which will contain
complete business logic and control the interaction between the
user, the model, and the view.
2Interceptors object that is invoked at the preprocessing
and postprocessing of a request. i.e validation, exception
handling, etc., Create interceptors if required, or use existing
interceptors. This is part of Controller.
3Value stack a stack that contains action objects, other
model objects. During execution, action is placed on the top of
the stack.
3
View - Create a JSPs to interact with the user to take
input and to present the final messages.
4
Configuration Files - Create configuration files to couple
the Action, View and Controllers. These files are struts.xml,
web.xml, struts.properties.
5

R. LOGAMBIGAI, TA

December 8, 2016

Struts 2 Basic Flow

1. User sends a request for the action


2. Controller invokes the ActionInvocation
3. ActionInvocation invokes each interceptors and action
4. A result is generated
5. The result is sent back to the ActionInvocation
6. A HttpServletResponse is generated
7. Response is sent to the user
6

R. LOGAMBIGAI, TA

December 8, 2016

Users Request Life Cycle

R. LOGAMBIGAI, TA

December 8, 2016

Users Request Life Cycle


1. User sends a request to the server for requesting for some
resource (i.e pages).
2. The FilterDispatcher looks at the request and then
determines the appropriate Action.
3. Configured interceptors functionalities applies such as
validation, file upload etc.
4. Selected action is executed to perform the requested
operation.
5. Again, configured interceptors are applied to do any postprocessing if required.
6. Finally the result is prepared by the view and returns the
result to the user

R. LOGAMBIGAI, TA

December 8, 2016

JSF
Java Server Faces (JSF) is a MVC web framework that
simplifies the construction of user interfaces (UI) for
server-based applications by using reusable UI components
in a page.
The JSF specification defines a set of standard UI
components and provides an Application Programming
Interface (API) for developing components. JSF enables the
reuse and extension of the existing standard UI
components.

R. LOGAMBIGAI, TA

December 8, 2016

Benefits of JSF
proving reusable UI components

making easy data transfer between UI components


managing UI state across multiple server requests
enabling implementation of custom components
wiring client side event to server side application code

10

R. LOGAMBIGAI, TA

December 8, 2016

JSF Architecture
MVC design pattern designs an application using three separate
modules:
Module
Description
Model
Carries Data and login
View
- Shows User Interface
Controller Handles processing of an application.
A JSF application is similar to any other Java technology-based web
application; it runs in a Java servlet container, and contains
JavaBeans components as models containing application-specific
functionality and data
A custom tag library for representing event handlers and validators
A custom tag library for rendering UI components

11

R. LOGAMBIGAI, TA

December 8, 2016

JSF Architecture
UI components represented as stateful objects on the
server
Server-side helper classes
Validators, event handlers, and navigation handlers
Application configuration resource file for configuring
application resources

12

R. LOGAMBIGAI, TA

December 8, 2016

JSF Architecture

13

R. LOGAMBIGAI, TA

December 8, 2016

JSF Life Cycle


JSF application lifecycle consist of six phases which are
as follows
Restore view phase
Apply request values phase; process events
Process validations phase; process events
Update model values phase; process events
Invoke application phase; process events
Render response phase

14

R. LOGAMBIGAI, TA

December 8, 2016

JSF Life Cycle

15

R. LOGAMBIGAI, TA

December 8, 2016

AJAX
AJAX stands forAsynchronousJavaScript andXML. AJAX is
a new technique for creating better, faster, and more
interactive web applications with the help of XML, HTML, CSS
and Java Script.
Ajax uses XHTML for content and CSS for presentation, as
well as the Document Object Model and JavaScript for
dynamic content display.
AJAX allows web pages to be updated asynchronously by
exchanging small amounts of data with the server behind the
scenes. This means that it is possible to update parts of a web
page, without reloading the whole page.
Classic web pages, (which do not use AJAX) must reload the
entire page if the content should change.

16

R. LOGAMBIGAI, TA

December 8, 2016

AJAX
Conventional web application transmit information to and from
the sever using synchronous requests. This means you fill out a
form, hit submit, and get directed to a new page with new
information from the server.
With AJAX when submit is pressed, JavaScript will make a
request to the server, interpret the results and update the
current screen.

17

R. LOGAMBIGAI, TA

December 8, 2016

Working of AJAX

18

R. LOGAMBIGAI, TA

December 8, 2016

AJAX Is Based On Open Standards


Browser-based presentation using HTML and Cascading Style
Sheets (CSS)
Data stored in XML format and fetched from the server
Behind-the-scenes data fetches using XMLHttpRequest objects
in the browser
JavaScript to make everything happen

19

R. LOGAMBIGAI, TA

December 8, 2016

Ruby
Ruby is a pure object oriented programming language.
Ruby is a general-purpose, interpreted programming language like
PERL and Python.
Ruby Syntax:
Whitespace characters such as spaces and tabs are generally
ignored in Ruby code, except when they appear in strings.
Ruby interprets semicolons and newline characters as the ending
of a statement. However, if Ruby encounters operators, such as +,
-, or backslash at the end of a line, they indicate the continuation
of a statement.
Identifiers are names of variables, constants, and methods. Ruby
identifiers are case sensitive. It mean Ram and RAM are two
different identifiers in Ruby.
Ruby comments start with a pound/sharp (#) character and go to
EOL. R. LOGAMBIGAI, TA
December 8, 2016
20

Ruby
Ruby Data Types:
Basic types are numbers, strings, ranges, arrays, and hashes.
Variable Types:
$global_variable
@@class_variable
@instance_variable
[OtherClass::]CONSTANT
local_variable

21

R. LOGAMBIGAI, TA

December 8, 2016

Ruby
Ruby Pseudo-Variables:
They are special variables that have the appearance of local
variables but behave like constants. You can not assign any value to
these variables.
self: The receiver object of the current method.
true: Value representing true.
false: Value representing false.
nil: Value representing undefined.
__FILE__: The name of the current source file.
__LINE__: The current line number in the source file.

22

R. LOGAMBIGAI, TA

December 8, 2016

Ruby Operators and Precedence

23

Top to bottom:
:: .
[]
**
-(unary) +(unary) ! ~
*/%
+<< >>
&
|^
> >= < <=
<=> == === != =~ !~
&&
||
.. ...
=(+=, -=...)
not
and or
R. LOGAMBIGAI, TA

December 8, 2016

Ruby - Control Expressions


1. if bool-expr [then]

body
elsif bool-expr [then]
body
else
body
end
2. unless bool-expr [then]
body
else
body
end
24

R. LOGAMBIGAI, TA

December 8, 2016

Ruby - Control Expressions


3. expr if bool-expr
4. expr unless bool-expr
5. case target-expr
when comparison [, comparison]... [then]
body
when comparison [, comparison]... [then]
body
...
[else
body]
end

25

R. LOGAMBIGAI, TA

December 8, 2016

Ruby - Control Expressions


6. loop do
body
end
7. while bool-expr [do]
body
end
8. until bool-expr [do]
body
end

26

R. LOGAMBIGAI, TA

December 8, 2016

Rails
An extremely productive web-application framework.
Written in Ruby.
You could develop a web application at least ten times faster
with Rails than you could with a typical Java framework.
An open source Ruby framework for developing databasebacked web applications.
Your code and database schema are the configuration!
No compilation phase required.

27

R. LOGAMBIGAI, TA

December 8, 2016

Features of Rails
Metaprogramming :Other frameworks use extensive code
generation from scratch. Metaprogramming techniques use
programs to write programs. Ruby is one of the best languages for
metaprogramming, and Rails uses this capability well. Rails also uses
code generation but relies much more on metaprogramming for the
heavy lifting.
Active Record :Rails introduces the Active Record framework,
which saves objects to the database. The Rails version of Active
Record discovers the columns in a database schema and
automatically attaches them to your domain objects using
metaprogramming.
Convention over configuration:Most web development frameworks
for .NET or Java force you to write pages of configuration code.
If you follow suggested naming conventions, Rails doesn't need
much configuration.
28

R. LOGAMBIGAI, TA

December 8, 2016

Rails
Scaffolding:You often create temporary code in the early stages
of development to help get an application up quickly and see how
major components work together. Rails automatically creates much
of the scaffolding you'll need.
Ajax at the core: Ruby on Rails has a great support for Ajax
technology and it is part of the core libraries.
Built-in testing:Rails creates simple automated tests you can then
extend. Rails also provides supporting code called harnesses and
fixtures that make test cases easier to write and run. Ruby can
then execute all your automated tests with the rake utility.
Three environments:Rails gives you three default environments:
development, testing, and production. Each behaves slightly
differently, making your entire software development cycle easier.

29

R. LOGAMBIGAI, TA

December 8, 2016

Ruby on Rails MVC Framework

30

R. LOGAMBIGAI, TA

December 8, 2016

Ruby on Rails MVC Framework


Model (ActiveRecord)
Maintains the relationship between Object and Database
and handles validation, association, transactions, and more.
This subsystem is implemented inActiveRecordlibrary
which provides an interface and binding between the
tables in a relational database and the Ruby program code
that manipulates database records.
Ruby method names are automatically generated from the
field names of database tables, and so on.
Active Record also provides dynamic attribute-based
finders and a number of other helper methods that make
database interaction easy and efficient.
31

R. LOGAMBIGAI, TA

December 8, 2016

Ruby on Rails MVC Framework


View (ActionView)
A presentation of data in a particular format, triggered by
a controller's decision to present the data. They are
script based templating systems like JSP, ASP, PHP and
very easy to integrate with AJAX technology.
This subsystem is implemented inActionViewlibrary which
is an Embedded Ruby (ERb) based system for defining
presentation templates for data presentation. Every Web
connection to a Rails application results in the displaying of
a view.
Action View really helps to separate the details of
presentation from the core business logic of your
application.
32

R. LOGAMBIGAI, TA

December 8, 2016

Ruby on Rails MVC Framework


Controller (ActionController)
The facility within the application that directs traffic, on
the one hand querying the models for specific data, and on
the other hand organizing that data (searching, sorting,
massaging it) into a form that fits the needs of a given
view.
This subsystem is implemented in ActionController which
is a data broker sitting between ActiveRecord (the
database interface) and ActionView (the presentation
engine).

33

R. LOGAMBIGAI, TA

December 8, 2016

References
http://www.exadel.com/tutorial/jsf/jsftutorial-kickstart.html

34

R. LOGAMBIGAI, TA

December 8, 2016

35

R. LOGAMBIGAI, TA

December 8, 2016

Vous aimerez peut-être aussi