Tanmoy Banerjee
Tanmoy Banerjee

Reputation: 1453

Confusion in Struts 2 MVC architecture

I am studying the Struts2 in Action and come to know that Controller in Struts 2 is FilterDispatcher and Model is Action.

But previously I knew that Action and FilterDispatcher both are Controllers and Struts does not provide support to Model layer. Which one of the above is wrong?

Upvotes: 1

Views: 436

Answers (2)

Roman C
Roman C

Reputation: 1

Actually Struts2 Actions are controller delegates. And Struts2 provides a valueStack on the View layer which has an Action on top of it, and if you want to use a pseudo-model then action should implement ModelDriven interface.

You should also note that Struts2 actions are simple POJOs managed by Struts2 container. This is a bit different in the MVC point of view, also known as MVC Model2. For example, the description of the model given by wikipedia:

The central component of MVC, the model, captures the behavior of the application in terms of its problem domain, independent of the user interface.[5] The model directly manages the data, logic and rules of the application.

From this point of view a Business Model is defined separately from the View Model and often being managed by Persistence layer. Struts2 controller works with the View Model via its delegates.

The View can be any output representation of information, such as a chart or a diagram; multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants.

In Struts2 the View is a Result returned by the controller in response object. Struts2 can use different result types and templates to produce a response.

The Controller, accepts input and converts it to commands for the model or view[6].

Struts2 uses a request for the input, which is handled by the Action to find appropriate delegate, which can work with the View Model directly or use a Service layer.

In Struts2 an Action is a Controller, it's a simple POJO which is also a Model.

Struts2 can help you with the Controller via ActionSupport and presenting a View, it's also pushes Action to the valueStack to have access from the View. You can design a Model via associating your Business Model with the View Model.

Upvotes: 0

Denis Borovikov
Denis Borovikov

Reputation: 747

I would say that FilterDispatcher is a FrontController and Action is both Model and Controller in one class.

Upvotes: 1

Related Questions