WebRatio Platform Architecture and MVC

Web Application Architecture
429 views Published on Apr 10, 2015 | Time 10 min
Applies to: 7.2 or higher

WebRatio Platform provides you with a set of predefined elements that allow you to model around 90% of the features that are commonly needed by a Web application. However, the remaining 10% may require custom business logic, or integration with a specific external system. Although it is not possible to have a built-in solution for all your Web application needs, you can address them by developing custom components and operations. This means that you will always be able to use WebRatio Platform to create applications that match your requirements. To do this, you first need to know more about the architecture of both WebRatio Platform and the Web applications developed with it. This lesson gives you an overview of WebRatio Platform’s architecture as well as of the "Model-View-Controller" (or MVC) pattern, which is used for the resulting Web application.

Transcript

Table of contents

Introduction

WebRatio Platform provides you with a set of predefined elements that allow you to model around 90% of the features that are commonly needed by a Web application. However, the remaining 10% may require custom business logic, or integration with a specific external system.

Although it is not possible to have a built-in solution for all your Web application needs, you can address them by developing custom components and operations. This means that you will always be able to use WebRatio Platform to create applications that match your requirements.

To do this, you first need to know more about the architecture of both WebRatio Platform and the Web applications developed with it. This lesson gives you an overview of WebRatio Platform's architecture as well as of the "Model-View-Controller" (or MVC) pattern, which is used for the resulting Web application.

WebRatio Platform Architecture

The overall architecture of WebRatio Platform includes two main parts:

  • WebRatio Platform Development Environment, which supports the design-time activities of application development, including the specification of the application site views and the generation of the application code.
  • WebRatio Platform Runtime, which enables the execution of Java Web applications generated by WebRatio Platform, and offers a feature-rich execution framework for page templates and business components.

Developing a Custom Component requires that you know about the structure of both parts of WebRatio Platform. The definition and execution of a custom component requires you to address both design-time and run-time issues.

Model-View-Controller

The Architectural Pattern used for Web applications generated with WebRatio Platform is "Model-View-Controller" (or MVC). The MVC Pattern logically splits the application into three layers representing the three essential functions of an interactive application:

  • The "Model", the state and business logic of the application.
  • The "View", the interface presented to the user.
  • The "Controller", the set of rules that update the model based on the events that happen within the user interface.

By decoupling "Model" and "View", MVC helps to reduce the complexity in the architectural design and increases flexibility and reuse of code. Available technologies and frameworks for developing Web applications are commonly designed according to the MVC Pattern. The "Controller", the "Model" and the "View" are developed in separated phases, but without being completely independent from one another. Indeed, the user interface is designed according to the functionalities of the application, and a change in a layer has consequences in the other layers.

"Model"

The domain-specific representation of the data on which the application operates. Domain Logic adds meaning to raw data, for example: calculating whether today is the user's birthday; or the totals, taxes, and shipping charges for shopping cart items. Many applications use a persistent storage mechanism, such as a database, to store data. MVC does not specifically mention the data access layer because it is understood to be underneath, or encapsulated by, the "Model".

"View"

Renders portions of the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.

"Controller"

Processes and responds to events, typically user actions, and may invoke changes on the "Model".

Request Lifecycle in MVC

In the MVC Architecture, a computation is activated by a user's request for some content or service.

The request is intercepted by the "Controller", which is responsible for deciding which action should be performed in serving the request. The "Controller" dispatches the request, in the form of a request for action, to the suitable component of the "Model".

The "Model" incorporates the business logic for performing the action and executes the logic, which updates the state of the application and produces a result to be communicated to the user.

The change in the "Model" triggers the most appropriate "View".

The "View" then builds the presentation of the response to the user.

The presentation typically embodies interaction objects, whereby the user may pose a new request and reactivate the computation process.

MVC and WebRatio Platform

Web applications generated by WebRatio Platform follow the MVC Pattern, somewhat adapted to take into account the peculiarity of the Web context, and to address some implementation issues.

Each tier is implemented according to a specific technology.

The runtime environment runs on the Java JEE architecture.

The "Controller" is implemented as a set of Struts servlets, while the "View" is implemented by means of JSP templates with custom tags for serving HTML pages.

As for the "Model", each element becomes a set of resources used by this architecture.

WebRatio Platform Components and MVC

The MVC Pattern splits a Web application into separate layers that can be analyzed, and sometimes implemented, separately. MVC Architecture separates out the three essential functions of an interactive application:

  • The business logic of the application: the "Model".
  • The control of the interaction triggered by the user's actions: the "Controller".
  • The interface presented to the user: the "View".

All applications generated with WebRatio Platform share the same software architecture, which is a classical three-tier architecture, enhanced to take advantage of a well-known software engineering design pattern, called "Model View Controller" - MVC.

The main elements of a WebRatio Platform application correspond to the IFML concepts of "Pages", "View Components", and "Operations".

Page Elements

Each modeled page is mapped into four elements:

  • A "Page Action" in the "Model".
  • A "Page Service" in the "Business Tier".
  • A "JSP Template" in the "View".
  • A "Page Action" in the "Controller’s configuration file.

The "Page Action" is an instance of a Java class, sometimes called an action class, which is invoked by the "Controller" when the user requests the page.

The HTTP request coming from the client is ultimately extracted by the "Page Action" class, which calls the "Page Service" in the "Business Tier", passing the needed parameters to it.

When the page processing terminates, the "Page Action" notifies the "Controller" that the page content is ready to be displayed.

The "Page Service" is a business function that supports the computation of the content of a page. At the end of the "Page Service" execution, a set of Java objects storing the content of the page components called "Component Beans" are available to the "View".

The page template is a "JSP Template", which computes the HTML page to be sent to the user, based on the content of the "Model".

The template contains the static HTML needed to define the layout where the components are positioned, and "Custom Tags" implementing the rendition of the content of components. Finally, the action mapping is a declaration placed in the Controller’s configuration file that ties together the user’s request, the "Page Action", and the page template.

View Components Elements

Each WebRatio Platform component maps into two components of the MVC architecture: a "Component Service" in the business layer and a set of "Custom Tags" in the "View".

A "Component Service" is a Java class that computes the component’s content, and produces a collection of "Component Beans" holding the content of the Component.

The Class encapsulates the instructions needed to assemble the data retrieval query, execute it, and package the results into suitable "Component Beans".

"Custom Tags" are required to implement the page templates of the "View" to transform the content stored in the "Component Beans" into HTML.

Such tags can be taken from a standard tag library, or defined specifically to match the features of your components.

Operation Elements

Operations map to three components of the MVC architecture:

  • An "Operation Action" in the "Model", which is similar to a "Page Action".
  • An "Operation Service" in the business layer, which is similar to a "Component Service".
  • An "Action Mapping" in the Controller’s configuration file, which dictates the flow of control after the "Operation Action" completes the execution.