wood burning stoves 2.0*
The moose likes Struts and the fly likes Design Patterns in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Design Patterns in Struts" Watch "Design Patterns in Struts" New topic
Author

Design Patterns in Struts

Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
Hi Guys,

I am new in Struts.

I have just started reading Struts and i am wondering in MVC is the only pattern we can apply if we are using Struts Framework?


Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
Yeah, thats the whole point of having such a framework isn't it?
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
yes, all you have to do is go to the struts home page and read a few lines and you'll see that's the point of it. What were you looking to use struts for?
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

MVC isn't the only pattern Struts uses. If you for example uses Struts 2 it uses the FrontController pattern wich is a helper pattern for MVC.

It uses Service To Worker pattern internally, Intercepting filter pattern and some more I guess.

When using tiles with Struts you are in fact using the Composite View pattern. When you build your model you probably will be using the Session Facade pattern, Data Access Object pattern and some more.

Read about them at Sun
[ June 07, 2007: Message edited by: Mathias Nilsson ]

SCJP1.4
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
Thanks for your comments!!

I remember in one interview i was asked what is a difference between Front Controller and MVC pattern. I never thought about it and I answered that Front Controller has only one controller which takes user input/requests whereas in MVC you can have several controller (thought this is not recommended). Is that correct?

I am new to Struts as i said, and i am reading programming in jakarta Struts and finding it ok but not sure if that book was designed for newbies considering.

Please let me know which book to read (i am use to head first series where lot of things are explained using daigrams...) so that concepts of Struts are clear.

Thanks!
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
I think that the Front Controller helps you not to write scriplet code in the JSP view. A Front Controller typically uses an Application Controller, which is responsible for action and view management.

The front controller is in struts 2 a Filter that functions as a Dispatcher for the action and views. The acion collects data and the Dispatcher forwards to the view. To preserve the Service To Worker pattern we don't want the action to be aware of the view. The dispatcher let's the action know to collect data and then forwards to JSP or other views.

If you find a good book on Struts 2 then please let me know. I'm looking for one
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
I tried going through struts on the struts website and wiki and it was a pain!!! It's so scatter-brain, I thought it was pretty bad. Anyway I did find this link through it all and this download is pretty well written and goes through the basics of Struts 2 and how to get things done, once you go through this you'll have a good foundation for the new framework.

http://www.infoq.com/minibooks/starting-struts2

You do have to signup on this site, but once you, you can download it. I thought it was a lot better than the struts 2 website. Let me know what you think of it.

Oh and I got this link from the struts 2 website:
http://struts.apache.org/ under recent threads: it's the link called: "Starting with Struts2" Book
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

From my opinion Struts 1.x also using Front Controller, since it is only using 1 servlet (ActionServlet) as controller. Then the controller will dispatch all the incoming requests to the apropriate Action class. You can read about Front Controller pattern here java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
Yes, Correct. Thats what i exactly wanted to say.

Thanks for the link.
Vyas
Greenhorn

Joined: May 21, 2007
Posts: 17
Good to know this. I was unaware of this!
 
Don't get me started about those stupid light bulbs.
 
subject: Design Patterns in Struts
 
Similar Threads
Setting up JDBC for Struts 1.2
unable to validate using struts 1.2.2 version
Double Iteration
why struts why not servlets?
client side validation vs server side validation