aspose file tools*
The moose likes Servlets and the fly likes Model 2 Controller/Action  Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Model 2 Controller/Action  Design" Watch "Model 2 Controller/Action  Design" New topic
Author

Model 2 Controller/Action Design

Dave Montalvo
Greenhorn

Joined: Sep 17, 2003
Posts: 5
There's an article at java.sun.com about the Model2 architecture and they have some code snippets outlining how it might be implemented. One section of this code is confusing me. Basically the idea is to have an abstract Action class that is extended by whatever specific actions you need.



but the article doesn't really talk about a Model class (see Action.java). Anyone have any ideas what protected Model model; is, or where it might come from, what it might contain?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The model objects are those that deal directly with the database, EJBs, filesystem, etc..
They should not need a servlet container or any of the javax.servlet.. classes to run.
Separating your code this way allows you to test your objects from the command line or with automated tools. It also allows you to reuse the model objects from non-servlet apps if you so desire.

Many developers, (myself included) like to see the model components running on the command line before touching a line of servlet or JSP code. Leaving the main method in your model classes is also useful for debugging later.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
After a good explaination of Ben. I would like to add-up my few words.

We all know Model contains our business logic. So we can say a Model could be a business component. And whenever we talk about component we think to re-use it some elsewhere or with some other system, and etc.

Model component shouldn't be dependent on client. No matter it is a web/thin client; with JSF, AJAX etc., or a thick client. No matter we are using SOA or not. No matter it is a desktop or client/server application. Our Model component should work with all.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Many developers, (myself included) like to see the model components running on the command line before touching a line of servlet or JSP code.


Fantastic! What great advice!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tim Morrison
Greenhorn

Joined: Oct 27, 2005
Posts: 5
While actually smalltalk started it all, Java makes it fine as silk. What I have seen in developers mostly is that they like to talk about data and business logic. From there, they move on workflow managment, and valiadtions in pages.
Ben has a pragmatic point. Incremental testing for a component developer, in this case EJB developer is usually, to test and re-test the business logic. command line is the immediate choice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Model 2 Controller/Action Design
 
Similar Threads
Web Application Framework
sun example Model datatype
Spring mvc annotation
MVC without Struts: A doubt
RequestDispatcher.forward problem