Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Views, Single Action

 
Bloo Barton
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general it seems that the rule is for each View there is a corresponding Action. This is part of our traditional MVC design pattern.

However, I have several different Views that essentially perform the same Action on form submission. Is there anything wrong in this case with having a many to one relationship, where I have many views to a single action? What are my pros and cons here?

thanks,
Bloo
 
Bloo Barton
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or what if I have a seperate Action class for each view, but an additional CommonAction class that is called by the view specific Actions classes?
 
Pranav Sharma
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from what I understand, you could have 1-1 relationship for action and views. But this just increases number of action classes which may become unmanagable. So if most of your action classes are doin similar tasks on different views, you could use DispatchAction and reduce the redundant cut and paste code.
bottom line 1 view to many relationships is good for similar tasks
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to map Struts to the traditional principles of MVC does not always make sense because Struts is not traditional MVC.

I'm not sure what you are referring to by "view". I assume you are referring to your jsps. There is nothing wrong with making more than one jsp call the same action but there's probably a good chance that you could take advantage of reusing your jsp.

Or what if I have a seperate Action class for each view, but an additional CommonAction class that is called by the view specific Actions classes?

I think that is not a good idea as it is an unnecessary chaining of Actions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic