Grails - MVC Architecture



Grails follows MVC platform for web application development. Grails has built-in MVC architecture support. The pattern is organized in 3 layers:

  • Model − It is representing and managing data stored in our application.

  • View − It is responsible for showing the state of our data models, and also the actions that they can execute.

  • Controller − This component receive orders from the user, manage the interaction between model and view, and decides which view should be displayed.

MVC pattern is a software architecture that isolates the application logic from the user interface layer. The MVC design pattern allows efficient code reuse and parallel development. The MVC concept can be graphically represented as follows.

Grails MVC

The Controller

The controller responds to user input and performs interactions on the data model objects. The controller receives input, validates it, and then performs required operations that modify the state of the data model. The controller is responsible for transferring the domain to view, and also determines which gsp should render the view.

The Model

The model is responsible for managing application data. It responds to the instructions from controller to update itself and it will request the controller for view of the data. Grails provides you a binded mechanism that help you references your model from the grails UI components. In Grails, data models are defined as domain classes.

The View

A presentation of data in a particular format, triggered by the controller's decision to present the data. Views in Grails are developed using Groovy Server Pages (GSP), which is a simplified JSP version. JSP version allows to place expressions within HTML code and use JSTL like tags.

Advertisements