wood burning stoves 2.0*
The moose likes Struts and the fly likes why not pass ActionForm instance to Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why not pass ActionForm instance to Model" Watch "why not pass ActionForm instance to Model" New topic
Author

why not pass ActionForm instance to Model

Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
Hello,

Why shouldn't we pass ActionForm instances to the Model. I read somewhere that it causes high coupling. If true, so what.

I am not able to understand the practical dis-advantages of passing an ActionForm instance. What problems may it cause?

regards,
vijay.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here's a scenario that might help explain it:

Say you decide to ignore the advice and pass your ActionForms as parameters to your model classes. Everything will work great, all is well, life is good.

Until.....

Your boss or client comes to you and says, "The CEO read in a airline magazine that JSF with AJAX is really the way to go, and Struts is really out of date. I want you to convert this application to JSF and Ajax."

You're thinking: OK, it's cool, I've used Model/View/Controller. I can just take the Model code that I've written and plug it into a JSF view.

Wrong!!

Since you made your Model class dependent on a Struts class (org.apache.struts.action.ActionForm) as soon as you remove struts.jar from your project, the model classes will no longer compile. You now have the choice of leaving the struts.jar file in the project just to make the project compile, or change your model classes.

The moral of the story: Tightly coupling your model classes with Struts or any other view framework is a bad thing.
[ July 05, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
OMG! I have my every model extend ActionForm and did something like...

public class Applicant
{
NameFormBean name;
ApplicationInfoFormBean applicationInfo;
}

where all those members extend ActionForm!!!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why not pass ActionForm instance to Model