Thursday, December 19, 2013

JAVASERVER FACES LESSON 3 – MODEL-VIEW-CONTROLLER ARCHITECTURE


JavaServer Faces from the start was created to adhere precisely to the MVC design pattern. The JSF framework is responsible for interacting with client devices, and it provides tools for tying together the visual presentation, application logic, and business logic of a web application.
The MVC pattern’s purpose is to decouple Model (or data) from the presentation of the data (View). The Controller handles user actions that might result in changes in the model and updates to the views. The scope of JSF is restricted to the presentation layer and its purpose is to connect the view to the model.
An MVC application is segmented into three distinct application components:
  • The Model, which contains the business logic or non-UI code
  • The View, which is all the code necessary to present a UI to the user
  • The Controller, which is a front-end agent that directly handles the user’s requests and dispatches the appropriate view
Let’s see how these three elements are combined to our simple Hello1 application to produce an architecture that yields distinct, separately maintainable code.





 

JSF connects the view and the model. A view component can be wired to a bean property of a model, such as:

The JSF implementation operates as the controller that reacts to the user by processing action and value change events, routing them to code that updates the model or directs the user to a new page. For example:


When the user clicks the button and the form is submitted to the server, the JSF implementation sets the value of the name property of the hello bean. Then the Faces Controller which is implemented as a servlet responds to the request by preparing an object known as the JSF context, which contains all accessible application data and routes the client to the appropriate View component (page). 
 
Michail Kassapoglou
Michail.Kassapoglou@gmail.com

0 comments: