Sie sind auf Seite 1von 2

Dynamic Controlling of Flow in Structs application

This document discusses about the method to control the flow of struts application dyanmically
with redeploying the application.

The Struts Framework uses ActionMapping class which is used to transfer the control from an
Action class to another resource. There are two ways to specify the next resource in the flow.

1. Using the <forward> tag in the <action-mapping> of the Struts-Config.xml file.

2. By creating the new instance of the ActionForward.

In most of the applications the first way is used to control the flow. Even when the second
method is used the destination resource is hardcoded or read from a constants/properties file, but
most of the times it is specific to a action.

One of the solution would be to move the control logic to a custom ActionMapping class so that
the flow of control across resources can be controlled dynamically which doesn't require the
redeployment.

The mapping information can be maintained in a database or in an xml.

The solution discussed here makes use of a xml to maintain the mapping information.

As getting the information from a Database/ reading an XML is an expensive operation we use
a Singleton class which implements the Runnable interface, this class reads mapping information
at regular intervals and stores it in a local Map object.
A Custom ActionMapping class is created which extends the Structs provided ActionMapping.
The custom ActionMapping class can be associated with the <action> using the attribute
classname.

The forward method is overridden to pass the control to next resource location, this method
looks for the presence of the resource in the Map object which gets updated at regular intervals,

i. if it is available this creates a new instance of ActionForward with the resource location

ii. if not, the ActionForward corresponding the forwardname in the structs-config.xml is


returned.

This gives the flexibity to control the flow dynamically in the Struts applications.

Example:

Let us look at an example , in a typical checkout process there could be steps selecting
the date of delivery, specifying the shipping sddress, billing information, order summary and order
confirmation.

On New Year day if business wants to show a promotion just before the order
confirmation, the development team need to modify the code to handle this.

With the above solution just with dynamically controlling the ActionForward that moves the
control from the Billing Page to Order Confirmation to point to the new Promotion page, the
business requirement can be fulfilled just with a configuration.

Das könnte Ihnen auch gefallen