File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes How to practice the web tire design patterns? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "How to practice the web tire design patterns?" Watch "How to practice the web tire design patterns?" New topic
Author

How to practice the web tire design patterns?

Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
Hi,

I have read the first few chapters of "Core J2EE Patterns" regarding the web tire and I am now trying to develop a simple web application that implements the patterns. I went to the blueprints web site and found the "Adventure Builder" web application which is interesting. However, the implementation heavily depends of the "Web Application Framework WAF" developed by the blueprints team. I tried to search on the net about this framework but could not find any resources. Some people say that WAF is not supported and that Struts or JSF should be used instead.

I am totally lost now and do not know what to do . All that I need to do is to develop a simple application to practice the patterns. Can any one guide me please to the right direction.

Happy Holidays,

Basel Mahdi
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think you had better go first with MVC Model 2. You will find enough resources about how to implement MVC and its simpler too.

If need some more help, why we are here .

cheers.
Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
I am already familiar with Model 2 and I have used it before. What confuses me is that the Adventure builder application uses classes from WAF such as DAOFactory, TemplateServlet and others which I think they are part of the patterns. Are they part of the pattern? Should I implement these classes to practicle and learn the pattern?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Mustafa,

Dont know about your Adventure Builder app. But WAF, as it calls itself, is a framework consist of different design pattern. Struts is a framework too, based on MVC, and command pattern. I call MVC as an architecture not the pattern, why?? dont know .

DAO, Data Access Object, is a Design Pattern used for database access specifically. Factory is an other pattern. DAOFactory sounds like the factory that provides a no. of DAOs to your application.

Yes you should implement these pattern in your application. At this stage no matter it is gonna be useful for you or not. Just to learn the pattern. Then after getting command on these pattern, you will know how, where, and when these or any of these should be used.

I suggest you to go for DAO alone, Factory alone, just to get the pattern itself. Then go for DAOFactory.

And lets see what other folks suggest.
I am not a whiz. just kidding
[ December 26, 2004: Message edited by: Adeel Ansari ]
Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
Thank you Adeel for spending the time replying to the confusion I am in.

All that I need is a simple way to practice the web tire patterns without reinventing the wheel. WAF, Struts or JSF might have implemented part of the patterns as part of their arcitecture to simplify the development process.

Can you guide me to a simple way to learn the patters independent of a specific web application framework?

Thanks,

Basel Mahdi
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Have a look here on J2EE Design Patterns and GoF Design Patterns. And Head First Design Pattern is a nice book, and some folks say, "its a mendatory".

Moreover, as you said you are sound with MVC Model2. I suggest you to start with some mostly used Patterns like, FrontController, Command Pattern, Value Object (VO), Data Access Object (DAO), Singleton, Factory.

Note: VO also known as Transfer Object (TO) and Replicate Object (RO).
Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
Thank you Adeel again.

As I said, I have read the first chapters of 'Core J2EE Patterns' and I am familiar with all the patterns that you mentioned. What I need now is to practice them independent of any specific web application framework.

Any guidance is greatly appreciated.

Thanks,

Basel Mahdi
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Mustafa,
What I can say now. Go ahead with any sample app given in your book.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
My project recently had several requirements to generate some web pages very quickly and outside the regular framework (which requires some applets, dlls and a very specific versio of IE). I made a servlet and a couple classes that are the whole framework for these pages. For GET or POST either one it does roughly this:

The command.execute() method can do any processing it likes. Ours make calls to an EJB backend. They put some data on the request and set the nextJSP name. The JSPs grab the data off the request and build the next page.

There is a bit more ... a configuration file maps the actionid to a command classname. There is optional declarative security - the user must have a specified resource access to get to a command. But even so, you can do a pretty decent little MVC-flavored framework in a hundred lines of code.


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
Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
Thank you Adeel and James.

Unfortunately Adeel, the 'Core J2EE Patterns' book does not have a complete application. It explains the concepts and gives some code snippets to give an idea how the pattern should be implemented.

James, can you tell me whether the Command and CommandFactory classes that you have in your project are part of an existing framework such as Struts or part of your own design and implementation.

Thanks,

Basel Mahdi
[ December 27, 2004: Message edited by: Basel Al-Mustafa ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Ok, it is a brief explaination.

In one of my semester project (2 years back) I didn't use struts (i didn't heard about struts that time ), but command pattern. I implemented command pattern via a HashMap. There was only one servlet controller. In my HashMap I mapped all the Command Handler Objects at the time of servlet initialization, even the Map itself instantiated in init() method of my servlet.

I had a parameter called 'action' in all my jsps, and all the requests were entertained by that servlet controller. Servlet used to check the parameter 'action' and pass the request to the appropriate command handler object. Further processing used to be done by command handler. Then back to servlet in order to send the response to the client.

Servlet controller knows where to send the response, means on which jsp page. There were DAOs just below the Command Handlers for database access, but forget it now.

You can go with Command Pattern like this, offcourse if you would like to. Your command handler could implement singleton pattern, means only one instance per command handler. You can call your HashMap as a Command Factory.

cheers.
[ December 27, 2004: Message edited by: Adeel Ansari ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Right on. The command pattern usually has an interface with an execute() kind of method and a bunch of implementing classes. My ICommand interface literally has one method execute(request, response, control); I showed the "nextJSP" as part of the command to simplify a bit, but in reality there is a single instance of each command class and the nextJSP variable is on that control parameter ... a simple structure of three or four public fields.

I have a separate CommandFactory class because it has a little logic to read configuration and I didn't want that bit in the servlet. But it's really just a HashMap with some window dressing.

My configuration maps an actionid to a command classname, a default next JSP and an optional security resource name. If that's present, the user must have permission to access the resource in our security tables. I made a logon command that authenticates the user and sets up a few session variables to support security checking.

I started by trying to make the absolute minimal framework with one servlet, one command interface. The security bit is about the only extension so far.
Basel Al-Mustafa
Greenhorn

Joined: Nov 27, 2004
Posts: 27
Thank you Adeel and James for you help.

I think I have an idea now about what need to be implemented and what need not to be implemented.

Thanks again,

Basel Mahdi
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Stan,
I did the something like similar and after gettin you i am sure it was not a bad implementation.

Mustafa,
I think you can try it now. Wishing you luck.
[ December 29, 2004: Message edited by: Adeel Ansari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to practice the web tire design patterns?
 
Similar Threads
simple project
Can I directly use the WAF in the part 2 solution?
WAF Web Controller and EJB Controller
WAF or JSF in SCEA 5 Part 2
Where to put the Business Delegate?