April - 2008 - issue > Technology
Suresh Reddy
Monday, March 31, 2008
Web applications have tremendously evolved since the early days of simple dynamic websites. The Web based user interface (UI) is the de facto UI for all applications, within the enterprise or beyond on the Internet. In the present evolved form, application models, design patterns, and frameworks are extensively used and this poses a challenge to development teams to evaluate and adopt the right model and frameworks for their projects. This article discusses the various Web frameworks available today, specifically comparing the frameworks available in Model2 architecture.

A typical Web applications development structure was a set of dynamic pages mixing up presentation, business logic, and data representation in one file. Issues with this approach: it is hard to manage the applications and one can’t re-use the application code. Typical enterprise applications requirement is easy manageability i.e., adding or removing functionality, changing UI view, and changing the flow without disturbing the code base.
The applications contain a mixture of data access code, business logic code, and presentation code. The typical requirement is to provide the same core functionality to evolve into different systems i.e., support multiple types of users with multiple types of interfaces. The same enterprise data needs to be presented in different views (HTML, XML and WML).

The Model View Controller (MVC) approach helps in simplifying the web application development and addresses the above mentioned problems by dividing the application into: Model-data modeling real world, View- display and presentation, and Controller- respond to user actions.

Advantages of MVC
* Re-use of Model components
* Easier support for new types of clients
* De-coupling of presentation and business logics
* Central point of control
* Facilitates unit-testing and maintenance
* Provides stability
* Simplifies internationalization
* Simplifies validation
MVC can be implemented in two ways.

Model-1 (Page-centric)
Offers simple page flow, with business logic embedded into the pages. Here, the model and view are well separated, but the control is embedded into the pages.
Flow composed of a series of interrelated JSP pages. Application logic and control decisions are hard coded inside JSPs in the form of JavaBeans, scriptlets, expressions.

Although Model-1 is suitable for simple applications, this architecture usually leads to the use of a significant amount of scriptlets (Java code in HTML).
This approach combines Controller and View functionalities within a JSP page, and therefore breaks the MVC

Model-2 (Servlet-centric)
Addresses the inadequacies of Model-1 approach by separating the layers into View, Model, and Controller. Provides a flexibility to build and maintain medium and large applications.

In MVC2, application is split into layers: presentation (UI), domain logic, and data access. Presentation layer is further separated into View and Controller.
Model-2 frameworks

A Web application framework is a reusable design for a software system to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities used in Web development.

Frameworks also provide well defined extension mechanisms to add new capabilities, services, etc., without disturbing the base structure.

Few Frameworks which support MVC2
* Struts
* Spring
* Wicket
We will now compare and contrast some of these frameworks here.
Struts, the first Model-2 framework
Struts is built upon standard technologies like Servlets, JavaBeans, ResourceBundles, and XML.
* Independent application modules can be configured through a single Controller.
* Uses SwitchAction to move between applications.
* Provides in-built validation support; extensible.

Typical Struts Flow
Controller: The controller servlet ensures that requests get routed, handled, and rendered.
Model: ActionForm and Action classes are responsible for handling HTTP Request data.
View: Typically JSPs (may use Taglibs to pull data from Model).
End-to-end flow:

* A popular Web application framework.
* Includes tag library for HTML presentation.
* Been in the market for many years; good user base and documentation.
* Several successful production systems were built using struts.
* Action forms, not so easy.
* Learning curve: Need to understand Servlet and JSP API well to get a hold on

* Can’t unit test.
* Most of the processing happens in the background; it is harder to analyze and optimize.

Spring MVC- abstracts the app server
Spring is a full-stack Java/JEE based application framework from SpringSource.
Spring is a strategic base platform for web application development; it also can integrate effortlessly with other frameworks. Spring is not tightly coupled with Servlets and Jsp to render the View.
* Every part of Spring MVC is configurable via plugging in your own interface.
* Controllers are configured via IoC like any other objects.
* Validation has no dependency on Servlet API.
* Spring allows choosing controller implementations to extend.
* Spring offers better integration with view technologies (Velocity, XSLT and XL.)

* Lifecycle for overriding binding, validation, etc.
* With many seamless view options: JSP/JSTL, Tiles and Velocity
* Inversion of Control makes it easy to test
* Configuration intensive- lots of XML
* Requires writing lots of code in JSPs
* Almost too flexible- no common parent Controller

JSF- standards based app-server neutral
JSF is a component oriented user interface framework for building Web applications that run on the server side and render the user interface back to the client.
JSF standards based framework developed through Java Community Process (JCP) makes it easy to build user interfaces for Java Web applications by assembling reusable components.

It is a suitable framework for building desktop-like functionalities. JSF Beans can act as both Model and Controller.
Model: JSF Benas and BL Beans
Controller: JSF Beans and FacesServlet represent
View: JSPs (with tags)
* Standards based frameworks (J2EE standard).
* Fast and easy to deploy.
* Rich Navigation framework.
* Very good event and interaction model.
* Tags in JSPs.
* Security is not defined properly.
* Multiple source of implementation.

Wicket- for rapid development of simple apps
Wicket is one of the recent component based Java Web frameworks from Apache. It is well suited for intranet and extranet applications where the UI is relatively complex.
In Wicket, server side state is automatically managed. Session state is associated with components. Each server-side page component holds a nested hierarchy of stateful components, where each component’s model is, in the end, a POJO. User session maintains a map of these pages.

* Good support for common Webisms (ajax and redirect after post)
* Powerful model abstraction
* Components are self contained and easy to create and use

* Great for Java developers, not Web developers.
* OO based.
* Tight binding between pages and views.
* Active community support from the creators.
* Uses the session extensively to store and render state. If not managed properly, it leads to very large session.
* HTML templates live next to Java code.
* Need to have a good grasp of OO.
* Less suited for projects where the UI is simple and largely read-only.
Choosing a framework for your project is always a challenge. While each framework has its strengths and weaknesses, not all frameworks are fit for all projects.
One needs to consider the following while choosing a framework:
* Suitability for your specific business needs.
* Performance.
* Support and community activity.
* Technology maturity.
* Developer prowess.
* Business relationships.
JSF is a standards based fast emerging framework; and as the framework is standards based any third-party feature can be integrated easily. Many App Server vendors now offer JSF implementations.

Spring MVC is highly configurable through interfaces and accommodates multiple view technologies. Spring can be easily integrated with applications with existing workflows defined. Struts provide simple navigation and good validation mechanisms. Most of the IDEs have support for Struts development.

Wicket is well suited for intranet and extranet applications, where the UI is relatively complex and you want to make the best use of your developer resources. It also provides support for flash based work.

Share on LinkedIn

Previous Magazine Editions