Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
By using this pattern, you separate your concerns into various layers of the application, just as you did with Data Transfer Objects (DTOs) and Data Access Objects (DAOs) in your service layer. If you’ve been developing Java-based web applications for a while, you’re probably familiar with some of the MVC frameworks that are available. The same concepts apply here, but as you’ll see, they’re implemented in a way that is a bit easier to use. Let’s look at the various components of the MVC design pattern and see how they’re implemented.
Model— The model layer of the application holds the data of the application and contains any business rules for manipulating that data. Your PRProduct object with its fields containing values for the name and serial number is part of your model and was generated by Service Builder. Any logic that would change those values based on certain rules would also be part of the model layer.
View— The view layer of the application contains all the logic for displaying the data to the user. Handling fields, check boxes, and other form elements, as well as hiding or showing data, are functions provided by the view layer. You’ll create JSPs that will handle the view layer, and you’ll see some tools that Liferay provides that makes this easy.
Controller— The controller layer acts as a traffic director. It passes data back and forth to and from the model and view layers, providing a separation of concerns. The controller, for example, might be responsible for determining which action a user has clicked and directing processing to the proper function to update the model. Generally, the model and view speak only to the controller, with the exception that the view may use objects from the model for display purposes (such as iterating over a List to populate a table).