Monday, April 6, 2009

Struts and MVC

The MVC design pattern calls for a separation of code by their function:
  1. Model: Code to control data access and persistence
  2. View: Code to handle how data is presented to the user
  3. Controller: Code to handle data flow and transformation between Model and View

With Struts, Controller code falls into three broad categories:
  • (1)
  • Simple validations are performed by your subclasses of the Struts base class called ActionForm. eg.Checks for password length or email address format are examples of this. Struts greatly simplifies validation with the Validator framework.
  • (2)
  • Complex validations and business logic are done in your subclasses of the Struts base class called Action. The check for the duplicate user ID for the Registration webapp is an example of complex validation. An example of business logic is calcu- lating the total amount due after a purchase in a shopping cart webapp.
  • (3)
  • Flow control is also decided by your Action subclasses, restricted to paths declared in the Struts configuration file called struts-config.xml.

No comments:

Post a Comment

Followers