Model View Control
Why
Reduce the complexity in architectural design, increase flexibility and maintainability. Write reusable (modular) software.
How
Decouple model from view and control. Put all the plumbing into corresponding super-classes.
Action
For each View create a JSF-page mypage.xhtml
and two Java
classes ViewMypage.java
and
ControllerMypage.java
.
The JSF-page defines the elements and the layout of the page.
Content is loaded and saved dynamically from the Java class
ViewMypage.java
. This Bean contains data from the model. Note: No
load, save or other model methods are called in this class.
Flow of control request (navigation) and model updates (computations) are channeld through
the class ControllerMypage.java
. Note: This class contains methods
which are called upon entering and leaving the page to ensure consistant data.
Example
Consider a page for retrieving a book. The JSF-page retrieve.xhtml contains elements for entering search information, a button to start the search, and a table to display author, title and keywords of the found books. Each row is a link to a JSF-page, where the contents of the book is displayed.
The Java-class ViewRetrieve.java
contains Getters and Setters for the
data to be displayed by the elements of the JSF-page retivieve.xhtml. Data is taken from a
local database which is maintained (updated) by the model.
The Java-class ControllerRetrieve.java
handles the action events and
page requests (navigation), i.e. calls model methods to search the books (which update the
database used by the View-class) and issues the request to navigate to the new page.
Date: 2011-02-11 Fr
HTML generated by org-mode 7.4 in emacs 22