Friday, June 8, 2007

Common Support class for Action classes

Create a support class for your actions and implement all the common logic for your actions in this class. Make this class extend ActionSupport and then in your action classes, just extend this support class. Following is a snippet of my ApplicationSupport class:

public class ApplicationSupport extends ActionSupport implements SessionAware, ParameterAware {
/**
* Field to store session context.
*/
private Map session;

/**
* Field to store request parameters.
*/
private Map parameters;

/**
* Result code for session expiry action.
*/
public final static String SESSION_EXPIRED = "SessionExpired";

...

You can handle following common concerns in the ApplicationSupport class:
1. Session
2. Parameters
3. Token
4. Validating session (though I would like to create an interceptor for this)
5. Common result codes etc.

ApplicationSupport class would reduce your action class code to a large extent by handling lot of common concerns in one centralized place.

No comments: