com.boylesoftware.cb2.presentation.servlet
Class ActionContext

java.lang.Object
  extended bycom.boylesoftware.cb2.presentation.servlet.ActionContext

public class ActionContext
extends java.lang.Object

Represents context of a CB2 action execution within a request processing. A correct instance of this class is always provided to actions and presentation elements.

Version:
$Id: ActionContext.java,v 1.12 2004/05/20 19:19:52 levahim Exp $
Author:
Lev Himmelfarb

Field Summary
static int APPLICATION_SCOPE
          Indicates the web-application scope for setAttribute, getAttribute and removeAttribute methods.
static int REQUEST_SCOPE
          Indicates the HTTP request scope for setAttribute, getAttribute and removeAttribute methods.
static int SESSION_SCOPE
          Indicates the HTTP session scope for setAttribute, getAttribute and removeAttribute methods.
 
Constructor Summary
ActionContext()
           
 
Method Summary
 void addComponentRef(java.lang.String refName, java.lang.String componentName)
          Calls addComponentRef(refName, componentName, null).
 void addComponentRef(java.lang.String refName, java.lang.String componentName, java.util.Map refAttributes)
          Adds a component reference to the list of component references associated with the page, which will be displayed as the result of this request processing.
 void addErrors(org.apache.struts.action.ActionErrors errors)
          Same as the saveErrors method, but does not overwrite any existing errors in the request.
 void addMessages(org.apache.struts.action.ActionMessages messages)
          Same as the saveMessages method, but does not overwrite any existing messages in the request.
 org.apache.struts.action.ActionForward findForward(java.lang.String name)
          Convenience method, which calls findForward on the action mapping in this context.
 org.apache.struts.config.ActionConfig findPageMapping(java.lang.String pageName)
          Finds action mapping for the named page from pages configuration file.
 org.apache.struts.action.ActionMapping getActionMapping()
          Gets action mapping used to select the action.
 ApplicationContext getApplicationContext()
          Gets the application context.
 java.lang.Object getAttribute(java.lang.String attrName, int scope)
          Gets an attribute value from the specified scope.
 BLObject getBLO(java.lang.String bloName)
          Gets the named BLO.
 BLOContainer getBLOContainer()
          Gets BLO container for the current session.
 java.lang.String getBLSessionId()
          Finds corresponding BL session id for a request.
 org.apache.struts.action.ActionForm getForm()
          Gets form bean submitted to the action or null if no form is required by the action.
 java.util.Locale getLocale()
          Gets the user's currently selected locale.
 org.apache.commons.logging.Log getLog()
          Gets log to be used in the action.
 javax.servlet.http.HttpServletRequest getRequest()
          Gets the HTTP request.
 java.lang.String getRequestParameter(java.lang.String paramName)
          A shortcut method returning a named HTTP request parameter.
 java.lang.String getRequestURL()
          Gets complete URL requested by the client browser.
 org.apache.struts.util.MessageResources getResources()
          Gets the default message resources for the current module.
 org.apache.struts.util.MessageResources getResources(java.lang.String key)
          Gets the specified message resources for the current module.
 javax.servlet.http.HttpServletResponse getResponse()
          Gets the HTTP response.
 BLObject getSharedBLO(java.lang.String bloName)
          Returns the specified by name BLO from the BLManager's shared BLO container or null.
 UIState getUIState()
          Gets the UIState bean instance for the current session.
 void removeAttribute(java.lang.String attrName, int scope)
          Removes an attribute from the specified scope.
 void saveErrors(org.apache.struts.action.ActionErrors errors)
          Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required.
 void saveMessages(org.apache.struts.action.ActionMessages messages)
          Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required.
 void setAttribute(java.lang.String attrName, java.lang.Object value, int scope)
          Sets an attribute in the specified scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATION_SCOPE

public static final int APPLICATION_SCOPE
Indicates the web-application scope for setAttribute, getAttribute and removeAttribute methods.

See Also:
Constant Field Values

SESSION_SCOPE

public static final int SESSION_SCOPE
Indicates the HTTP session scope for setAttribute, getAttribute and removeAttribute methods.

See Also:
Constant Field Values

REQUEST_SCOPE

public static final int REQUEST_SCOPE
Indicates the HTTP request scope for setAttribute, getAttribute and removeAttribute methods.

See Also:
Constant Field Values
Constructor Detail

ActionContext

public ActionContext()
Method Detail

getApplicationContext

public ApplicationContext getApplicationContext()
Gets the application context.

Returns:
reference to the application context.

getSharedBLO

public BLObject getSharedBLO(java.lang.String bloName)
Returns the specified by name BLO from the BLManager's shared BLO container or null. The BLO names are case-insensitive.

In the most cases you should use the getBLO method on the BLOContainer from the action context, which can return both regular and shared BLOs. This method is here for those rare cases, when you do not have access to the BLOContainer but still need access to some shared BLOs. Such a situation is possible, for example, in a detached action.

Parameters:
bloName - the requested BLO's deployment name, case-insensitive.
Returns:
reference to the shared BLO or null.
See Also:
BLOContainer.getBLO(java.lang.String)

getRequestURL

public java.lang.String getRequestURL()
Gets complete URL requested by the client browser. This method returns the very first requested URL regardless of any forwards or includes during the request processing.

Returns:
complete URL requested by the client browser.

getUIState

public UIState getUIState()
Gets the UIState bean instance for the current session.

Returns:
reference to the UIState bean instance.

getBLSessionId

public java.lang.String getBLSessionId()
Finds corresponding BL session id for a request. The session ids in the BLManager are not the same as the HTTP session ids assigned by the Servlet Container. This method allows to find the BL session id for the HTTP request being processed.

Returns:
the BL session id.

getActionMapping

public org.apache.struts.action.ActionMapping getActionMapping()
Gets action mapping used to select the action.

Returns:
action mapping used to select the action.

getForm

public org.apache.struts.action.ActionForm getForm()
Gets form bean submitted to the action or null if no form is required by the action.

Returns:
form bean submitted to the action or null.

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Gets the HTTP request.

Returns:
the HTTP request.

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Gets the HTTP response.

Returns:
the HTTP response.

getBLOContainer

public BLOContainer getBLOContainer()
Gets BLO container for the current session.

Returns:
BLO container for the current session.

getLog

public org.apache.commons.logging.Log getLog()
Gets log to be used in the action.

Returns:
log to be used in the action.

getLocale

public java.util.Locale getLocale()
Gets the user's currently selected locale. The same as Struts' Action.getLocale method.

Returns:
the user's locale.

getResources

public org.apache.struts.util.MessageResources getResources()
Gets the default message resources for the current module. The same as Struts' Action.getResources method.

Returns:
the message resources.

getResources

public org.apache.struts.util.MessageResources getResources(java.lang.String key)
Gets the specified message resources for the current module. The same as Struts' Action.getResources method.

Parameters:
key - the key specified in the <message-resources> element for the requested bundle.
Returns:
the message resources.

saveErrors

public void saveErrors(org.apache.struts.action.ActionErrors errors)
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. Otherwise, ensure that the request attribute is not created. The same as Struts' Action.saveErrors method.

Parameters:
errors - errors to set, null or empty structure to clear the errors.

saveMessages

public void saveMessages(org.apache.struts.action.ActionMessages messages)
Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Otherwise, ensure that the request attribute is not created. The same as Struts' Action.saveMessages method.

Parameters:
messages - messages to set, null or empty structure to clear the messages.

getBLO

public BLObject getBLO(java.lang.String bloName)
Gets the named BLO. This is just a convenience method and its effect is exactly the same as calling getBLOContainer().getBLO(bloName).

Parameters:
bloName - the BLO's deployment name.
Returns:
the BLO instance.
See Also:
BLOContainer.getBLO(java.lang.String)

addErrors

public void addErrors(org.apache.struts.action.ActionErrors errors)
Same as the saveErrors method, but does not overwrite any existing errors in the request. If there are already some errors in the request this method will add the specified bundle to them.

Parameters:
errors - the errors to set/add.

addMessages

public void addMessages(org.apache.struts.action.ActionMessages messages)
Same as the saveMessages method, but does not overwrite any existing messages in the request. If there are already some messages in the request this method will add the specified bundle to them.

Parameters:
messages - the messages to set/add.

findForward

public org.apache.struts.action.ActionForward findForward(java.lang.String name)
Convenience method, which calls findForward on the action mapping in this context.

Parameters:
name - name of the action forward to find.
Returns:
named action forward from the context's action mapping.

findPageMapping

public org.apache.struts.config.ActionConfig findPageMapping(java.lang.String pageName)
Finds action mapping for the named page from pages configuration file. Note that this method looks only among pages defined for this Struts module.

Parameters:
pageName - name of the page.
Returns:
action mapping that points to the page or null if there is no page with the specified name.

getRequestParameter

public java.lang.String getRequestParameter(java.lang.String paramName)
A shortcut method returning a named HTTP request parameter. Calling this method is the same as calling actionCtx.getRequest().getParameter(paramName).

Parameters:
paramName - the HTTP request parameter name.
Returns:
the named parameter value or null.

getAttribute

public java.lang.Object getAttribute(java.lang.String attrName,
                                     int scope)
Gets an attribute value from the specified scope.

Parameters:
attrName - name of the attribute to retrieve.
scope - the scope, one of xxx_SCOPE constants.
Returns:
the attribtue value or null.

setAttribute

public void setAttribute(java.lang.String attrName,
                         java.lang.Object value,
                         int scope)
Sets an attribute in the specified scope.

Parameters:
attrName - name of the attribute to set.
value - the value to set in the attribute.
scope - the scope, one of xxx_SCOPE constants.

removeAttribute

public void removeAttribute(java.lang.String attrName,
                            int scope)
Removes an attribute from the specified scope.

Parameters:
attrName - name of the attribute to remove.
scope - the scope, one of xxx_SCOPE constants.

addComponentRef

public void addComponentRef(java.lang.String refName,
                            java.lang.String componentName)
                     throws javax.servlet.ServletException
Calls addComponentRef(refName, componentName, null).

Parameters:
refName - reference name to be used with the <cb2:insert> tag.
componentName - name of the corresponding component as defined in the pages-config.xml.
Throws:
javax.servlet.ServletException - if no component is defined under the specified name.
See Also:
addComponentRef(String, String, Map)

addComponentRef

public void addComponentRef(java.lang.String refName,
                            java.lang.String componentName,
                            java.util.Map refAttributes)
                     throws javax.servlet.ServletException
Adds a component reference to the list of component references associated with the page, which will be displayed as the result of this request processing. The static list of component references is associated with a page in its descriptors using <componentref> elements. This method allows to add additional component references to the list dynamically from actions, page pre-actions and presentation elements. Note, that this method adds a component reference to the end of the list, meaning that all the corresponding PEs, including any global PEs on which the component depends, will be initialized after all global and local PEs required by any components refered by the page statically via its descriptor, as well as after all PEs required by any components already added to the list using this method.

Parameters:
refName - reference name to be used with the <cb2:insert> tag.
componentName - name of the corresponding component as defined in the pages-config.xml.
refAttributes - component reference attributes, which can be used with component's presentation elements as input parameters with "from" attribute set to "crefattribute" or "any". This argument can be null.
Throws:
javax.servlet.ServletException - if no component is defined under the specified name.


Copyright © 2002,2003,2004 - Boyle Software, Inc.