Section 14.5. Model-View-Controller

   

14.5 Model-View-Controller

A chief goal of the JSP architecture was to keep presentation and application business logic separate. By offloading the real work of your page into a bean, you can help ensure that your JSPs are mostly HTML and then simple, readable variable references. You may hear developers talking about the Model 2 architecture or the Model-View-Controller architecture. This is simply a fancy way of saying that presentation and business logic separation is important, and that you can achieve this using a proven design pattern. That pattern is as follows : The model holds the data. The view retrieves the data and presents it to the viewer. The controller acts as a broker or router, delegating responsibilities to the model and the view.

Not to equate the two, but if you have used the Fusebox methodology with ColdFusion, you should be familiar with this concept. In Fusebox, you've got a central switch that is never viewed itself, but routes responsibilities to the different " fuses " in the application, and then everything is <cfinclude> ed.

Generally, a JavaBean represents the model, a JSP the view, and a servlet acts as the controller. Think back to the security example. We weren't using beans, but we had a DBUtil class that held the data, the JSP to show the dynamic information, and the servlet that controlled request routing.

When you use this architecture, you often don't need more tags than this. Now, I must seriously qualify that statement. Clients want the same kinds of things over and over. Everyone likes to upload a file, for instance, or update their job listings. It is therefore important to be able to quickly add functionality to disparate applications. It would be really nice if we had the convenience of a <jsp:file> tag in JSP. But we don't. We have to write it ourselves as a custom tag or bean, or find it somewhere else. Of course, as with custom ColdFusion tags one might need to modify the source in order to tailor it to specific needs.


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net