com.ibm.portal.struts.command
Class StrutsViewCommand

java.lang.Object
  extended by com.ibm.portal.struts.command.StrutsViewCommand
All Implemented Interfaces:
IViewCommand, java.io.Serializable
Direct Known Subclasses:
StrutsFilteredViewCommand, StrutsViewActionCommand, StrutsViewErrorCommand, StrutsViewJspCommand, StrutsViewXmlCommand

public abstract class StrutsViewCommand
extends java.lang.Object
implements IViewCommand, java.io.Serializable

Command pattern class used to provide a mechanism to encapsulate the information needed to redisplay a view. The StrutsViewCommand is the base class for all commands in the Struts Portlet Framework. The base class provides the methods to save all the attributes that need to be saved with the command, and provides the methods to repopulate the request attributes.

Since:
5.1
See Also:
Serialized Form

Field Summary
protected static java.lang.String CONTENT_TYPE
          Request attribute name for the content type.
protected static MessageResources messages
          The message resources for the Struts Portlet Framework.
protected static java.lang.String PREFIX
          Request attribute name for the prefix.
 
Constructor Summary
StrutsViewCommand()
          Default constructor.
StrutsViewCommand(PortletRequest request)
          Constructs the StrutsViewCommand object.
 
Method Summary
protected static void addAttribute(java.lang.Object attribute, java.util.List list)
          Adds the attribute to the list.
static void addAttributeNameToSave(java.lang.String attributeName)
          Adds the name of an attribute from the object request that needs to be saved if present for the execution of the IViewCommand in Portal's render phase.
static void addAttributeTypeToSave(java.lang.Class attributeType)
          Adds the class type of an attribute from the object request that needs to be saved if present for the execution of the IViewCommand in Portal's render phase.
 void execute(RenderRequest request, RenderResponse response, ViewCommandExecutionContext executionContext)
          Executes the given command given the request and response objects.
 java.lang.String getContentType(PortletRequest request)
          Returns the content type associated with this command.
 java.lang.String getPrefix(PortletRequest request)
          Returns the prefix associated with this command.
 boolean getRemoveOnModeChange()
          Returns the state of removeOnModeChange.
 java.util.Map getSavedAttributes()
          Returns the saved attributes map.
static IViewCommand getSavedCommand(PortletRequest request, PortletResponse response, ViewCommandExecutionContext context)
          Gets the saved command from the Command Manager Factory.
protected static void removeAttribute(java.lang.Object attribute, java.util.List list)
          Removes the attribute from the list.
static void removeAttributeNameToSave(java.lang.String attributeName)
          Removes the name of an attribute from the list of attribute names to save.
static void removeAttributeTypeToSave(java.lang.Class attributeType)
          Removes the class type of the request attribute from the list of attributes to save.
protected  void repopulateRequest(RenderRequest request)
          Repopulates the given request from saved values.
protected  void saveAsAttribute(java.lang.String name, java.lang.Object value)
          Saves the given named object for later restoral as an attribute for when the command is executed.
protected  void saveAttribute(PortletRequest request, java.lang.String name)
          Saves the given request attribute for later restoral when the command is executed.
 void saveAttributes(PortletRequest request, ViewCommandExecutionContext context)
          Saves attributes from the request by name for later restoral when the command is executed.
protected  void saveAttributes(PortletRequest request, ViewCommandExecutionContext context, java.util.List namesToSave, java.util.List typesToSave)
          Saves attributes from the request by name for later restoral when the command is executed.
 void saveCommand(PortletRequest request, PortletResponse response)
          Saves the current command using the Command Manager Factory.
 void saveCommand(PortletRequest request, PortletResponse response, java.lang.String commandPrefix)
          Saves the current command using the Command Manager Factory.
 void setContentType(PortletRequest request)
          Sets the content type.
 void setContentType(PortletRequest request, java.lang.String contentType)
          Sets the content type associated with this command.
 void setPrefix(PortletRequest request, java.lang.String prefix)
          Sets the prefix associated with this command.
 void setRemoveOnModeChange(boolean value)
          Allows setting a flag so that this command is removed when the Portal mode changes.
 void setSavedAttributes(java.util.Map attributeMap)
          Sets the saved attributes map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

protected static final java.lang.String CONTENT_TYPE
Request attribute name for the content type.

See Also:
Constant Field Values

PREFIX

protected static final java.lang.String PREFIX
Request attribute name for the prefix.

See Also:
Constant Field Values

messages

protected static MessageResources messages
The message resources for the Struts Portlet Framework.

Constructor Detail

StrutsViewCommand

public StrutsViewCommand()
Default constructor. If this constructor is used, the setPrefix method must be called to set the module prefix. Commands must save the module prefix so that the correct Struts module config can be set in the render phase of portal.


StrutsViewCommand

public StrutsViewCommand(PortletRequest request)
Constructs the StrutsViewCommand object. The module prefix will be determined from the request object. The StrutsViewCommand is typically created in the action phase of Portal, so the interface expects a PortletRequest.

Parameters:
request - The request object to save context information from
Method Detail

addAttributeNameToSave

public static void addAttributeNameToSave(java.lang.String attributeName)
Adds the name of an attribute from the object request that needs to be saved if present for the execution of the IViewCommand in Portal's render phase.

Parameters:
attributeName - the name of the attribute

removeAttributeNameToSave

public static void removeAttributeNameToSave(java.lang.String attributeName)
Removes the name of an attribute from the list of attribute names to save.

Parameters:
attributeName - the name of the attribute

addAttributeTypeToSave

public static void addAttributeTypeToSave(java.lang.Class attributeType)
Adds the class type of an attribute from the object request that needs to be saved if present for the execution of the IViewCommand in Portal's render phase.

Parameters:
attributeType - the attribute type

removeAttributeTypeToSave

public static void removeAttributeTypeToSave(java.lang.Class attributeType)
Removes the class type of the request attribute from the list of attributes to save.

Parameters:
attributeType - the attribute type

getSavedCommand

public static IViewCommand getSavedCommand(PortletRequest request,
                                           PortletResponse response,
                                           ViewCommandExecutionContext context)
                                    throws PortletException
Gets the saved command from the Command Manager Factory.

Parameters:
request - the portlet request object
response - the portlet response object
context - the view command execution context
Returns:
returns the saved IViewCommand object
Throws:
PortletException - if the request cannot fulfilled

saveCommand

public void saveCommand(PortletRequest request,
                        PortletResponse response)
                 throws PortletException
Saves the current command using the Command Manager Factory.

Parameters:
request - The request object
response - the response object
Throws:
PortletException

saveCommand

public void saveCommand(PortletRequest request,
                        PortletResponse response,
                        java.lang.String commandPrefix)
                 throws PortletException
Saves the current command using the Command Manager Factory.

Parameters:
request - The request object
response - the response object
commandPrefix - the prefix to store the command
Throws:
PortletException

setContentType

public void setContentType(PortletRequest request)
Sets the content type. This method will determine the content type from the request object if the request object is an ActionRequest object.

Parameters:
request - the portlet request object

repopulateRequest

protected void repopulateRequest(RenderRequest request)
Repopulates the given request from saved values. The request attributes that were saved as part of the saveAttributes call are repopulated in the render phase of Portal. This method should only be called from this class's execute method.

Parameters:
request - The request object to repopulate

saveAttributes

protected void saveAttributes(PortletRequest request,
                              ViewCommandExecutionContext context,
                              java.util.List namesToSave,
                              java.util.List typesToSave)
Saves attributes from the request by name for later restoral when the command is executed.

Parameters:
request - The request object to save attributes from
context - the view command execution context
namesToSave - a list of the attribute names to save
typesToSave - a list of the types to save

saveAttribute

protected void saveAttribute(PortletRequest request,
                             java.lang.String name)
Saves the given request attribute for later restoral when the command is executed.

Parameters:
request - the request object to get attribute from
name - the name of the attribute to save

saveAsAttribute

protected void saveAsAttribute(java.lang.String name,
                               java.lang.Object value)
Saves the given named object for later restoral as an attribute for when the command is executed.

Parameters:
name - of attribute to save
value - the value to store

saveAttributes

public void saveAttributes(PortletRequest request,
                           ViewCommandExecutionContext context)
Saves attributes from the request by name for later restoral when the command is executed.

Parameters:
request - The request object to save attributes from
context - the view command execution context

getSavedAttributes

public java.util.Map getSavedAttributes()
Returns the saved attributes map. The saveAttributes method should be called before calling this method.

Returns:
returns the map of saved attributes.

setSavedAttributes

public void setSavedAttributes(java.util.Map attributeMap)
Sets the saved attributes map. Can set the attributes before execute is called which will repopulate the request object with the saved attributes.

Parameters:
attributeMap - the map of attributes.

setRemoveOnModeChange

public void setRemoveOnModeChange(boolean value)
Allows setting a flag so that this command is removed when the Portal mode changes.

Parameters:
value - true will cause this command to get removed

getRemoveOnModeChange

public boolean getRemoveOnModeChange()
Returns the state of removeOnModeChange.

Returns:
returns true if comamnd should be removed on mode change.

getPrefix

public java.lang.String getPrefix(PortletRequest request)
Returns the prefix associated with this command.

Parameters:
request - the request object
Returns:
returns the prefix

setPrefix

public void setPrefix(PortletRequest request,
                      java.lang.String prefix)
Sets the prefix associated with this command.

Parameters:
request - the request object

getContentType

public java.lang.String getContentType(PortletRequest request)
Returns the content type associated with this command. The content type is the mime type that was determined from the request.

Parameters:
request - the portlet request
Returns:
returns the content type

setContentType

public void setContentType(PortletRequest request,
                           java.lang.String contentType)
Sets the content type associated with this command.

Parameters:
request - the portlet request
contentType - the content type

execute

public void execute(RenderRequest request,
                    RenderResponse response,
                    ViewCommandExecutionContext executionContext)
             throws PortletException
Executes the given command given the request and response objects. This implementation should be called by subclasses. The execute method is always called in the render phase of Portal, so the request and response objects are the RenderRequest and RenderResponse objects.

Specified by:
execute in interface IViewCommand
Parameters:
request - The request object
request - The response object
executionContext - the execution context object
response - the response object
Throws:
PortletException - if the request cannot be fulfilled

addAttribute

protected static void addAttribute(java.lang.Object attribute,
                                   java.util.List list)
Adds the attribute to the list. Caller is assumed to have synchronized the list.

Parameters:
attribute - the attribute to add to the list
list - the array list to update

removeAttribute

protected static void removeAttribute(java.lang.Object attribute,
                                      java.util.List list)
Removes the attribute from the list. Caller is assumed to have synchronized the list.

Parameters:
attribute - the attribute
list - the array list to update