• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Model 2 Front controller?

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I read Bear's article "Scriptless JSP Pages: The Front Man" and found it very informative. I pretty much understood what was going on, but just wanted to make sure this makes sense using to you guys. So basically in a Model 2 all requests come into the front controller and then the controller delegates out to certain command classes based on a configuration. I was a little confused as to where this config is kept? I was thinking I could do something like this. Let me know if this sounds correct?

Say I had a jsp and you could either view, update, delete, or create something. Could I just set a request parameter called method send the request to the front controller, have a switch on the method parameter, and then create whatever command class I needed to delegate out to based on the method name? For example if I passed ?method=delete id=1 then the front controller could created a DeleteCommand class do the deletion and then redirect to the view controller which would then fwd back to the jsp? Does this make sense?

Thanks,

AMD
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Mcmurray wrote:... Say I had a jsp and you could either view, update, delete, or create something. Could I just set a request parameter called method send the request to the front controller, have a switch on the method parameter, and then create whatever command class I needed to delegate out to based on the method name? For example if I passed ?method=delete id=1 then the front controller could created a DeleteCommand class do the deletion and then redirect to the view controller which would then fwd back to the jsp? Does this make sense?

Yep sounds correct, make sure your view controller prepares the JSP(s) accordingly. You may want to check for frameworks like Struts, Spring MVC etc... to see how these are implemented in real world.

[Edit]Corrected a misspelled word[/Edit]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Mcmurray wrote:I read Bear's article "Scriptless JSP Pages: The Front Man" and found it very informative.
Thank you!

So basically in a Model 2 all requests come into the front controller and then the controller delegates out to certain command classes based on a configuration.

Sort of. A Front Controller isn't absolutely necessary to adhere to Model 2. All that matters is that each page has a controller that prepares the page, rather than trying to do this with Java code in the JSPs themselves. These controllers can each be individual servlets. But that gets messy really fast. The Front Controller helps to tame this messiness.

I was a little confused as to where this config is kept?
It depends upon the Front Controller implementation. My FrontMan implementation uses a lot of "configuration by convention", along with annotations, and (as a last resort) property files. Others might use XML or other configuration mechanisms.

Take a look at FrontMan (link in my sig) if you'd like to see a simple implementation without all the bells and whistles (and complexity) of behemoth frameworks like Struts or SpringMVC.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys! Bear, I will check out your Front Man impl. I need something without all the bells and whistles bc I am not sure how accepting my new project will be of me if I start demanding we need to implement a new framework The Web app is not too too big, so I think I can kill two birds with one stone. Make the jsps more scriptless and move at least the new code to more of a Model 2.

Thanks,

AMD
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Mcmurray wrote:... and whistles bc I am not sure...

Please UseRealWords when posting as it might confuse the reader
 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Mcmurray wrote:Thanks guys! Bear, I will check out your Front Man impl.

I love Bear's FrontMan. Its great.
 
Mike Heffelfinger
Greenhorn
Posts: 13
Chrome Tomcat Server Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like Front Man too :thumbup: ... simple and powerful. I wrote a couple of articles on using it in simple applications.

Sample Hello World Front Man JAVA web application
Example Java web application using Google App Engine with Front Man
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic