com.cc.framework.adapter.struts
Class ActionUtil

java.lang.Object
  extended bycom.cc.framework.adapter.struts.ActionUtil

public abstract class ActionUtil
extends java.lang.Object

Utility methods for Action derived classes

Since:
1.0
Version:
$Revision: 1.2 $
Author:
Gernot Schulz
See Also:
Action

Field Summary
private static java.lang.String ERR_ACTION
          Error message
private static java.lang.String ERR_ACTION_CTRL
          Error message
private static java.lang.String ERR_ACTION_HANDLER
          Error message
private static java.lang.String ERR_FIND_CONTROL
          Error message
private static java.lang.String ERR_FORMACTION
          Error message
private static org.apache.commons.logging.Log log
          Private Logger instance
 
Constructor Summary
ActionUtil()
           
 
Method Summary
static void applyControlStates(FrameworkAction action, ActionContext ctx)
          Applies the serialized control state from the HTTPRequest to the corresponding control instances.
static ActionContext createActionContext(FrameworkAction action, org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This method is called to create the ActionContext wrapper.
static void doRenderAjaxResponse(FrameworkAction action, ActionContext ctx, javax.servlet.jsp.PageContext pageContext)
          Renders the AJAX XML response
static void execute(FrameworkAction action, ActionContext ctx)
          Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it).
static java.lang.reflect.Method getActionHandler(FrameworkAction action, ControlRequestContext ctx, java.lang.Object[] params)
          Searches the action class for a handler method.
static Control getControlByName(FrameworkAction action, ActionContext ctx, java.lang.String name)
          The framework has a default pattern where to search a control instance.
static java.lang.reflect.Method getFormHandler(FrameworkAction action, FormActionContext ctx, java.lang.String methodName)
          Searches the action class for a handler method.
static ActionContext handleControlAction(FrameworkAction action, ActionContext ctx, ControlMethodInvocation cmi)
          Handles an action which comes from a control on the form an delegates the request to the control.
static void handleControlAction(FrameworkAction action, ControlActionContext ctx, java.lang.Object[] params)
          Handles an action which comes from a control on the form.
static ActionContext handleFormAction(FrameworkAction action, ActionContext ctx)
          Checks if the request comes from a form button (save, cancel, ...) and delegates the request to the corresponding handler for the button which must be implemented in the (action) subclass.
static boolean isValidFormProperty(java.lang.Object bean, java.lang.String name)
          Checks the given form for a valid property
static java.util.Locale localeFromName(HttpContext context, java.lang.String localeName)
          Gets the Locale Object from a Locale Name
static java.util.Locale localeFromSession(HttpContext context)
          Gets the Locale Object for the running session
static java.lang.String localize(HttpContext context, java.lang.String keyOrString)
          Localizes a string depending on the localization settings of the Painter context.
static java.lang.String localize(HttpContext context, java.lang.String keyOrString, java.util.Locale locale)
          Localizes a string depending on the localization settings of the Painter context.
static java.lang.String localize(HttpContext context, java.lang.String keyOrString, java.lang.Object[] arguments)
          Localizes a string depending on the localization settings of the Painter context.
static java.lang.String localize(HttpContext context, java.lang.String keyOrString, java.lang.Object[] arguments, java.util.Locale locale)
          Localizes a string depending on the localization settings of the Painter context.
static java.lang.String localize(HttpContext context, java.lang.String keyOrString, java.lang.Object[] arguments, java.util.Locale locale, boolean returnNull)
          Localizes a string depending on the localization settings of the Painter context.
protected static void logControlAction(Control ctrl, java.lang.reflect.Method handler, java.lang.Throwable t)
          This method logs any exceptions that have occurred during the execution of a control event handler
static void removeFormBean(FrameworkAction action, ActionContext ctx)
          Helper function that removes the form bean which can either be located in the user's session or the request scope.
static void sendAjaxResponse(javax.servlet.http.HttpServlet servlet, FrameworkAction action, ActionContext ctx)
          This method gets called when the framework needs to render the dirty controls
static void setControlValue(FrameworkAction action, ActionContext ctx, ControlValuePath path, java.lang.String[] value)
          This method is called to set a control element value
static void setControlValuesFromRequest(FrameworkAction action, ActionContext ctx)
          This method is called to updates any control element data from request values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERR_ACTION

private static final java.lang.String ERR_ACTION
Error message

See Also:
Constant Field Values

ERR_ACTION_CTRL

private static final java.lang.String ERR_ACTION_CTRL
Error message

See Also:
Constant Field Values

ERR_ACTION_HANDLER

private static final java.lang.String ERR_ACTION_HANDLER
Error message

See Also:
Constant Field Values

ERR_FORMACTION

private static final java.lang.String ERR_FORMACTION
Error message

See Also:
Constant Field Values

ERR_FIND_CONTROL

private static final java.lang.String ERR_FIND_CONTROL
Error message

See Also:
Constant Field Values

log

private static org.apache.commons.logging.Log log
Private Logger instance

Constructor Detail

ActionUtil

public ActionUtil()
Method Detail

isValidFormProperty

public static boolean isValidFormProperty(java.lang.Object bean,
                                          java.lang.String name)
Checks the given form for a valid property

Parameters:
bean - form bean
name - property name
Returns:
returns true if the property is valid

removeFormBean

public static void removeFormBean(FrameworkAction action,
                                  ActionContext ctx)
Helper function that removes the form bean which can either be located in the user's session or the request scope.

Parameters:
action - The Action instance
ctx - The ActionContext

getControlByName

public static Control getControlByName(FrameworkAction action,
                                       ActionContext ctx,
                                       java.lang.String name)
                                throws java.lang.Exception
The framework has a default pattern where to search a control instance. If the control can not be found by the implemented pattern, this method can be overwritten to implement an additional or own processing. First the control will be searched in the session, then the control will be searched in the FormBean which is associated with the action.

Parameters:
action - The Action instance
ctx - The ActionContext
name - The name of the bean
Returns:
Control
Throws:
java.lang.Exception - If an exception occurred

handleControlAction

public static ActionContext handleControlAction(FrameworkAction action,
                                                ActionContext ctx,
                                                ControlMethodInvocation cmi)
                                         throws java.lang.Exception
Handles an action which comes from a control on the form an delegates the request to the control.

Parameters:
action - The Action instance
ctx - ActionContext
cmi - ControlMethodInvocation
Returns:
ActionContext
Throws:
java.lang.Exception - if an exception occurs

handleControlAction

public static void handleControlAction(FrameworkAction action,
                                       ControlActionContext ctx,
                                       java.lang.Object[] params)
                                throws java.lang.Exception
Handles an action which comes from a control on the form. If the subclass does not implement a special processing for this event, the event will be forwarded to the control. So the control can do some default processing. This default behavior can be changed if an event handler in the subclass is implemented. This handler must follow the naming convention "controlname_onEventname(ControlRequestContext ctx, parameters ...) For example: users_onDrilldown(ControlRequestContext ctx, String key) Note: An other way to change the default behavior of an existing control is to subclass the control an write an new control.

Parameters:
action - The Action instance
ctx - ControlRequestContext
params - Parameters
Throws:
java.lang.Exception - if an exception occurs

logControlAction

protected static void logControlAction(Control ctrl,
                                       java.lang.reflect.Method handler,
                                       java.lang.Throwable t)
This method logs any exceptions that have occurred during the execution of a control event handler

Parameters:
ctrl - The control instance
handler - The Action handler
t - The exception

getActionHandler

public static java.lang.reflect.Method getActionHandler(FrameworkAction action,
                                                        ControlRequestContext ctx,
                                                        java.lang.Object[] params)
Searches the action class for a handler method. The search order is

Parameters:
action - The Action instance
ctx - the action context
params - actual parameters
Returns:
returns a handler method or null when no such method is defined

getFormHandler

public static java.lang.reflect.Method getFormHandler(FrameworkAction action,
                                                      FormActionContext ctx,
                                                      java.lang.String methodName)
Searches the action class for a handler method. The search order is

Parameters:
action - The Action instance
ctx - the action context
methodName - the name of the method
Returns:
returns a handler method or null when no such method is defined

setControlValue

public static void setControlValue(FrameworkAction action,
                                   ActionContext ctx,
                                   ControlValuePath path,
                                   java.lang.String[] value)
                            throws java.lang.Exception
This method is called to set a control element value

Parameters:
action - The Action instance
ctx - The ActionContext
path - The Pathname of the value
value - The value itself
Throws:
java.lang.Exception - is thrown when a value could not be set

setControlValuesFromRequest

public static void setControlValuesFromRequest(FrameworkAction action,
                                               ActionContext ctx)
                                        throws java.lang.Exception
This method is called to updates any control element data from request values. All nested control element values follow the naming convention documented in ControlValuePath

Parameters:
action - The Action instance
ctx - The ActionContext
Throws:
java.lang.Exception - is thrown when a value could not be set

handleFormAction

public static ActionContext handleFormAction(FrameworkAction action,
                                             ActionContext ctx)
                                      throws java.lang.Exception
Checks if the request comes from a form button (save, cancel, ...) and delegates the request to the corresponding handler for the button which must be implemented in the (action) subclass. This handler must follow the naming convention "buttonname_onEventname(FormActionContext ctx) For example save_onClick(FormActionContext ctx)

Parameters:
action - The Action instance
ctx - The ActionContext
Returns:
ActionContext
Throws:
java.lang.Exception - If an exception occurred

createActionContext

public static ActionContext createActionContext(FrameworkAction action,
                                                org.apache.struts.action.ActionMapping mapping,
                                                org.apache.struts.action.ActionForm form,
                                                javax.servlet.ServletContext servletContext,
                                                javax.servlet.http.HttpServletRequest request,
                                                javax.servlet.http.HttpServletResponse response)
This method is called to create the ActionContext wrapper. Overwrite this method to use your own implementation

Parameters:
action - The Action instance
mapping - Struts Action Mapping
form - Struts Action Form
servletContext - the servlet context
request - HTTPServletRequest
response - HTTPServletResponse
Returns:
ActionContext whichis passed to the doExecute() method

applyControlStates

public static void applyControlStates(FrameworkAction action,
                                      ActionContext ctx)
                               throws java.lang.Exception
Applies the serialized control state from the HTTPRequest to the corresponding control instances.

Parameters:
action - The Action instance
ctx - ActionContext
Throws:
java.lang.Exception - if an exception occurs

execute

public static void execute(FrameworkAction action,
                           ActionContext ctx)
                    throws java.lang.Exception
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.

Parameters:
action - The Action instance
ctx - The ActionContext
Throws:
java.lang.Exception - if an exception occurred

sendAjaxResponse

public static void sendAjaxResponse(javax.servlet.http.HttpServlet servlet,
                                    FrameworkAction action,
                                    ActionContext ctx)
                             throws java.lang.Exception
This method gets called when the framework needs to render the dirty controls

Parameters:
servlet - the HTTP servlet
action - action instance
ctx - the ActionContext
Throws:
java.lang.Exception - Indicates an error during rendering

doRenderAjaxResponse

public static void doRenderAjaxResponse(FrameworkAction action,
                                        ActionContext ctx,
                                        javax.servlet.jsp.PageContext pageContext)
                                 throws java.lang.Exception
Renders the AJAX XML response

Parameters:
action - action instance
ctx - ActionContext
pageContext - PageContext
Throws:
java.lang.Exception - Indicates an error during rendering

localize

public static java.lang.String localize(HttpContext context,
                                        java.lang.String keyOrString)
Localizes a string depending on the localization settings of the Painter context.

Parameters:
context - JSP Page Context
keyOrString - String Literal or Resource Key
Returns:
localized String

localize

public static java.lang.String localize(HttpContext context,
                                        java.lang.String keyOrString,
                                        java.util.Locale locale)
Localizes a string depending on the localization settings of the Painter context.

Parameters:
context - JSP Page Context
keyOrString - String Literal or Resource Key
locale - Locale or null
Returns:
localized String

localize

public static java.lang.String localize(HttpContext context,
                                        java.lang.String keyOrString,
                                        java.lang.Object[] arguments)
Localizes a string depending on the localization settings of the Painter context.

Parameters:
context - JSP Page Context
keyOrString - String Literal or Resource Key
arguments - MessageFormat arguments or null
Returns:
localized String

localize

public static java.lang.String localize(HttpContext context,
                                        java.lang.String keyOrString,
                                        java.lang.Object[] arguments,
                                        java.util.Locale locale)
Localizes a string depending on the localization settings of the Painter context.

Parameters:
context - JSP Page Context
keyOrString - String Literal or Resource Key
arguments - MessageFormat arguments or null
locale - Locale or null
Returns:
localized String

localize

public static java.lang.String localize(HttpContext context,
                                        java.lang.String keyOrString,
                                        java.lang.Object[] arguments,
                                        java.util.Locale locale,
                                        boolean returnNull)
Localizes a string depending on the localization settings of the Painter context. A key is searched in the following order:
  1. If no user defined resource bundle is used. The resource is searched under the STRUTS_MESSAGES_KEY.
  2. If an user defined resource bundle is used (key@bundle) the resource is searched in the specified resource bundle.
  3. If the key was not found before, the resource is searched in the framework resource bundle under the key Globals.MESSAGE.

Parameters:
context - JSP Page Context
keyOrString - The String literal or resource key.
arguments - MessageFormat arguments or null
locale - Locale or null
returnNull - controls whether to return null or a not present indicator
Returns:
localized String

localeFromName

public static java.util.Locale localeFromName(HttpContext context,
                                              java.lang.String localeName)
Gets the Locale Object from a Locale Name

Parameters:
context - JSP Page Context
localeName - The Name
Returns:
Locale Object or null

localeFromSession

public static java.util.Locale localeFromSession(HttpContext context)
Gets the Locale Object for the running session

Parameters:
context - JSP Page Context
Returns:
Locale Object or null


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.