Kuldeept’s Weblog

Just another WordPress.com weblog

Archive for the ‘Java’ Category

Struts2 and DOJO

Posted by kuldeept on July 15, 2009

Now days everybody is talking about web2.0. Web 2.0 is facilitating communication, information sharing, interoperability and User-centered design. To achieve this user-web interactivity, web based frameworks (Struts2, Spring) and AJAX are key technologies.

Struts2 is a second-generation web based application framework that implements the Model-View-Controller (MVC) design pattern. Struts 2 is built from the ground upon best practices and proven, community-accepted design patterns. Using AJAX, you can increase the user interactivity on web to refresh certain part of web page without submitting complete page every time.

Recently, we worked on Sales Credit Adjustment Request Template for Sales Compensation Team. We have developed SCART application using Struts2 framework and dojo. We have used Struts2 framework to separate the UI (html) and core logic (java code). There were lots of features on this template where we had to update certain part of webpage without submitting the form/complete page. AJAX form submission helped us to achieve this. We have used dojo grid in this project that is a very nice widget provided by dojo framework which allow us to create data in grid format.

We are going to write in brief about Dojo and Struts2’s features that can help us to build more user interactive, scalable and maintainable web-based applications


One of the frameworks that make it easier to use Ajax is the DOJO JavaScript toolkit. This framework provides lots of already built-in widget that allow us to do faster development and enhance the interface and usability of web applications.

Dojo widgets are prepackaged components of JavaScript code; HTML markup and CSS style declarations that can be used to enrich websites with various interactive features that work across browsers:

  • Menus, tabs, and tooltips
  • Sortable tables, dynamic charts, and 2-D vector drawings
  • Animated effects—fades, wipes and slides—facilities for custom animation effects
  • Tree widgets that support drag-and-drop
  • Various forms and routines for validating form input
  • Calendar-based date selector, time selector, and clock

One of the widget that we had used in SCART application is Dojo Grid that expects data in json format and provides nicely build grid with sorting and pagination without any server side coding. This saves a lot of development efforts spent on sorting and pagination. Beside, this allows you to format data in desired format.

See in details about dojo and widgets available:



See in details how Grids works (http://www.sitepen.com/blog/2008/07/14/dojo-12-grid/).


Struts2 is web application framework. Struts2 helps well-designed web applications, as it provided the infrastructure for easily achieving the MVC separation of concerns. This allowed developers with few resources for such architectural niceties to tap into a ready-made best practice solution available to them.

Struts 2 introduce several new architectural features that make the framework cleaner and more flexible. These new features include interceptors for layering cross-cutting concerns away from action logic; annotation-based configuration to reduce or eliminate XML configuration; a powerful expression language, Object-Graph Navigation Language (OGNL), that transverses the entire framework; and a mini-MVC–based tag API that supports modifiable and reusable UI components. Hence, Apache Struts 2 is a dynamic, extensible framework for a complete application development from building, deploying and maintaining.

The high-level design of Struts 2 follows the well-established Model-View-Controller design pattern. The MVC pattern provides a separation of concerns that applies well to web applications. Separation of concerns allows us to manage the complexity of large software systems by dividing them into high-level components.

Struts 2 has lot of features of them are Interceptors. This provides ability to do an action before an event. For example we can write our own validations or any program that needs to be executed much before our main program starts, e.g., login functionality.

Secondly, it also its own tags that helps in minimizing amount of code to be written. For example if we need to construct an object then we need all its fields to be collected and then pass to constructor to get that object initialized. But in struts 2 we need to just give the names of the object fields in the html tags, on submit this itself will create a object this can be captured by just getter setter methods for that object. Even retrieval of the fields of the object is simple.

Furthermore, Struts 2 also has Ajax theme, which helps in implementation of the Ajax features. With the help of the struts.xml we can easily identify what action is done for what and what is the output of that action. With advent of the action methods in the action class we direct each method to each function and return the result appropriately. There is also feature for the CSS implementation with help of the property file. We can just provide the theme name in the property file this will apply for all the struts tags.

Struts 2 also provide validation framework. Our validation can be void with just making the field validate to true in the html forms.  Some key features provided by Struts2 are:

  • Simplified Design – Programming the abstract classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework. Framework components are tried to keep loosely coupled.
  • Simplified Actions  – Actions are simple POJOs. Any java class with execute() method can be used as an Action class. Even we don’t need to implement interfaces always. Inversion of Control is introduced while developing the action classes.
  • No more ActionForms  – ActionForms feature is no more known to the struts2 framework. Simple JavaBeans flavored actions are used to put properties directly. No need to use all String properties.
  • Simplified testability – Struts 2 Actions are HTTP independent and framework neutral. This enables to test struts applications very easily without resorting to mock objects.
  • Intelligent Defaults – Most configuration elements have a default value, which can be set according to the need. Even there are xml-based default configuration files that can be overridden according to the need.
  • Improved results – Unlike ActionForwards, Struts 2 Results provide flexibility to create multiple types of outputs and in actual it helps to prepare the response.
  • Better Tag features – Struts 2 tags enables to add style sheet-driven markup capabilities, so that we can create consistent pages with less code. Struts 2 tags are more capable and result oriented.
  • Annotations introduced: Applications in struts 2 can use java 5 annotations as an alternative to XML and Java properties configuration. Annotations minimize the use of xml.
  • Stateful Checkboxes – Struts 2 checkboxes do not require special handling for false values.
  • QuickStart – Many changes can be made on the fly without restarting a web container.
  • Easy plugins – Struts 2 extensions can be added by dropping in a JAR. No manual configuration is required!
  • AJAX support – The AJAX theme gives interactive applications a significant boost.
    The framework provides a set of tags to help you ajaxify your applications, even on Dojo. The AJAX features include:
  1. AJAX Client Side Validation
  2. Remote form submission support (works with the submit tag as well)
  3. An advanced div template that provides dynamic reloading of partial HTML
  4. An advanced template that provides the ability to load and evaluate javascript remotely
  5. An AJAX-only tabbed Panel implementation
  6. A rich pub-sub event model
  7. Interactive auto complete tag

Some of the useful links for struts 2





Posted in Java | Leave a Comment »