permaculture playing cards*
The moose likes Struts and the fly likes Topic: Struts and MVC. Question: how usually are working you? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Topic: Struts and MVC. Question: how usually are working you?" Watch "Topic: Struts and MVC. Question: how usually are working you?" New topic
Author

Topic: Struts and MVC. Question: how usually are working you?

Olexiy Prokhorenko
Ranch Hand

Joined: Jul 11, 2004
Posts: 97
Probably there were numerous topics on MVC and Struts, but I am starting this one again. :-)

There are many thoughs on applying MVC architecture to Web, and there is no one common and correct answer.
My question is a bit different.

How usually are YOU working with Struts?

I am using:

"View" --- JSP/HTML pages. The can access getters of "data" bean. They can have links/forms *.do
"Controller" --- classes which extends Action. I am usually implement all business logic there. Connecting to database, etc., etc., etc. Then it also use setters in "data" bean and then redirects where necessary.
"Model" --- it's our "data" bean, class which extends ActionForm , with getters and setters. It's doing nothing, just keep data.

What about you?

Of course, I understand that we can't assign so special actions to MVC. But we need to "understand" all these Model, View and Controller at least to ourself!


Will be waiting for your responses! It really interesting how are you building your Struts applications. Thank you in advance!
[ October 10, 2004: Message edited by: Olexiy Prokhorenko ]

<a href="http://www.BossTalks.com" target="_blank" rel="nofollow">http://www.BossTalks.com</a><br />Free advices and help for entrepreneurs: from Idea to IPO<br />Software and IT Project Management forum
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Olexiy !

In my view Action forms are not exactly part of Model. In MVC model is place where your business logic consist.

In action forms there is nothing to do with Model.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Olexiy Prokhorenko
Ranch Hand

Joined: Jul 11, 2004
Posts: 97
Shailesh,

Sorry, may be I was not very clear in my question.

I mean - where do you keep business logic in your Struts stuff?
In class extending Action? In class extending ActionForm? In JSP's?

Certainly, if we will try to assign MVC to Struts we probably could get that Model is partly class extending Action + class extending ActionForm, View is JSP/HTML, and Controller is partly class extending Action. But that's like neverending story. Everybody have own opinion on this topic, and we can argue about theory all the time, however, all of us will be right.

But the question is -- how do you use Struts in real-life applications? on practice?
Where do you you keep your BUSINESS LOGIC?


Thank you.
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
You are partly right.
Have you read these links on the struts site?
The Model: System State and Business Logic JavaBeans
The View: JSP Pages and Presentation Components
The Controller: ActionServlet and ActionMapping

"Controller" --- classes which extends Action. I am usually implement all business logic there. Connecting to database, etc., etc., etc. Then it also use setters in "data" bean and then redirects where necessary.

This what the user guide says:
For the simplest applications, an Action object may sometimes handle the business logic associated with a request. However, in most cases, an Action object should invoke another object, usually a JavaBean, to perform the actual business logic. This lets the Action focus on error handling and control flow, rather than business logic. To allow reuse on other platforms, business-logic JavaBeans should not refer to any Web application objects. The Action object should translate needed details from the HTTP request and pass those along to the business-logic beans as regular Java variables.

"Model" --- it's our "data" bean, class which extends ActionForm , with getters and setters. It's doing nothing, just keep data.

This what the user guide says:
While ActionForm beans often have properties that correspond to properties in your Model beans, the form beans themselves should be considered a Controller component. As such, they are able to transfer data between the Model and View layers.


I have not taken the trouble to explain the above in my own words, but I hope this information answers your question.
Sheldon Fernandes
[ October 11, 2004: Message edited by: Sheldon Fernandes ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Dear Olexiy,

Best Practice says the create a separate layer and call them from "action class" Flow should be like

Request-->ActionServlet-->Action-->"your Model/Logic Layer class"--> Session beans--> onwards

But 80% developer end up with putting their business logic in action class.

MVC architecture says that your "Model" should not be dependant any how on "Controller".But some how our action class are tight coupled with our controller.

but still your class extending action is only place to put more of business logic if not creating a saperate model layer.

This is my view , Others view may differ
Olexiy Prokhorenko
Ranch Hand

Joined: Jul 11, 2004
Posts: 97
Thanks guys, thank you for your advices!
They are very helpful. This was something like I though, I though that such structure has to exist, but never use it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Topic: Struts and MVC. Question: how usually are working you?