Monday, October 25, 2010

Tuesday, June 1, 2010

Model View Controller (MVC) Design Pattern

Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. The MVC (Model-View-Controller) architecture the client request is first intercepted by a servlet referred as controller servlet, this servlet handles the initial processing of the request and determines which JSP page to display next. Here the controller servlet is the single point of entry, there is a clear sepration of business logic, presentation output and request processing.

MCV architecture is a way of decomposing an application into three parts:

Model : The model contains the core of the application's functionality. The model encapsulates the state of the application. Sometimes the only functionality it contains is state. It knows nothing about the view or controller.The model maintains the state and data that the application represents.

View: The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.The view allows the display of information about the model to the user.

Controller: The controller reacts to the user input. It creates and sets the model.The controller allows the user to manipulate the application.

MVC Design Pattern comprised of two models.
  • MVC Model 1 is a Page Centric Architechure
  • MVC Model 2 is a Serlet Centric Architechure
Struts frame work extensively makes use of MVC 2 Architecture

MVC was originally applied in the graphical user interaction model of input, processing and output. In Struts, the view is handled by JSPs and presentation components, the model is represented by Java Beans and the controller uses Servlets to perform its action.

JAVA SERVER FACES (JSF)

JSF

A server side user interface component framework for Java-based web applications

A specification and reference implementation for a web application development framework

– Components
– Events
– Validators & converters
– Navigation
– Back-end-data integration

Struts and JSF can be used together

JSF provides Drag-and-drop UI components to build a web Application.

Next generation Web application framework based on component model

We can create JSF application by writing JSP pages yourself

JSF Basic Capabilities

* Extensible user interface (UI) component model

* Flexible rendering model

* Event and listener handling model

* Per-component validation framework

* Basic page navigation support

* Internationalization and accessibility

* Extensible Component and Rendering architecture

* Support for client device independence

* Huge vendor and industry support

JSF Concepts

UIComponent

Render-independent characteristics

Base class with standard behaviors

Standard UIComponent Subclasses

UICommand, UIForm, UIGraphic, UIInput, UIOutput, UIPanel,
UISelectBoolean, UISelectMany, UISelectOne

FacesEvent

Base class for request and application events

Validator

Base class for standard and application defined validators

Converter

Plug-in for String-Object conversion

FacesContext

– Servlet request, response, session
– JSF request, response trees
– Model reference expression evaluators

Syntax similar to the expression language of the JSP Standard Tag Library (JSTL) 1.x

Primary interface between components and the data provided by (or to) the application

JSF Key Concepts

Renderer

– Converts components to and from a specific markup language
– Supports render-dependent attributes on components
– May support more than one component type

RenderKit

– Library of Renderers
– Extensible at runtime
– Basic HTML RenderKit is part of the specification

JSF is based on:
– Servlet 2.3 (JSR-53)
– JSP 1.2 (JSR-53)
JSF must be synergistic with:
– JSTL 1.0 (JSR-52)
– Portals (JSR-168)
JSF is not part of J2EE 1.4 standard yet
– Will be considered for J2EE 5.0
– It is included in J2EE 1.4 SDK, however
JSF Built in classes

UIViewRoot

● UIViewRoot is a UIComponent that represents the root of the UIComponent tree.

● Serves as the root of the component tree,and as a place to hang per-view PhaseListeners

FacesContext

● Contains all of the per-request state information related to the processing of
a single JavaServer Faces request, and the rendering of the corresponding response.

● It is passed to, and potentially modified by,each phase of the request
processing lifecycle

PhaseListener

● An interface implemented by objects that wish to be notified at the beginning
and ending of processing for each standard phase of the request processing lifecycle

● You can provide your own implementation of PhaseListener and plug it
into the application for custom request handling – Ajax request handling

● Before and after each phase handling
– “around” semantics

Application Class

● Represents a per-web-application singleton object

● Maintains application wide objects

– set of supported locales
– converters
– validators

● Serves as a factory for creating components,converters, and validators
public abstract UIComponent createComponent(String componentType) throws FacesException