Java Reference
In-Depth Information
WAR STORY
Back when JSP was all the rage and the Y2K bug had not brought on the
worldwide nuclear destruction that we had been promised, I was working for a
small web start‐up. Our start‐up was composed of just a few JSP/Java developers
and some l ash designers. We wanted to build a website portal that would serve
dynamic content that depended on the specii c needs of the client that had
contracted us.
So we jumped into the project with 100 percent enthusiasm and developed a highly
dynamic website that displayed different features for different clients. We were truly
proud of our creation, and so were the many clients who bought our wonderful
site. In fact, we were becoming quite successful, and rather quickly, too. It seemed
that everyone was really happy with our product, and we were happy with our
success. But that happiness was short lived. As more and more clients bought our
product, the site became increasingly difi cult to manage. What we had done was
mix the business logic with the view logic, so for each new client, we had to amend
all the JSP in the site. Soon the JSP became a horrible mishmash of business and
display logic, and we ended up with unmanageable spaghetti code. It became a
nightmare, so we had no choice but to rewrite the entire application, but this time
implementing the MVC pattern.
We did rewrite the application, and it became manageable, but only after many
late nights and a lot of weekends spent in the ofi ce. The moral of this story is
that the MVC pattern is good, not only for your application's maintenance and
extensibility, but for your life‐work balance.
MVC Types
The MVC pattern comes in many different forms. The two most recognized are referred to as Type I
and Type II.
MVC Type I —This type is a page‐centric approach in which the view and the controller
exist as one entity referred to as the view‐controller. With this approach, the controller logic
is implemented within the view, such as in a JSF. All the tasks that the controller performs,
including retrieving HTTP request attributes and parameters, invoking the business logic,
and managing the HTTP session, are embedded in the view using scriptlets and tag libraries.
Type I highly couples the view generation with the application l ow, making maintenance
troublesome.
MVC Type II —The maintenance problems with Type I are overcome in Type II by moving
the controller logic out of the view and into a servlet, leaving the JSF to concern itself with
the rendering of the data for the view.
 
Search WWH ::




Custom Search