org.apache.struts2.dispatcher
Class StrutsResultSupport

java.lang.Object
  extended by org.apache.struts2.dispatcher.StrutsResultSupport
All Implemented Interfaces:
Result, Serializable, StrutsStatics
Direct Known Subclasses:
FreemarkerResult, PlainTextResult, PortletFreemarkerResult, PortletResult, PortletVelocityResult, ServletDispatcherResult, ServletRedirectResult, StreamResult, VelocityResult

public abstract class StrutsResultSupport
extends Object
implements Result, StrutsStatics

A base class for all Struts action execution results. The "location" param is the default parameter, meaning the most common usage of this result would be:

This class provides two common parameters for any subclass:

NOTE: The encode param will only have effect when parse is true

In the struts.xml configuration file, these would be included as:

  <result name="success" type="redirect">
      <param name="location">foo.jsp</param>
  </result>

or

  <result name="success" type="redirect" >
      <param name="location">foo.jsp?url=${myUrl}</param>
      <param name="parse">true</param>
      <param name="encode">true</param>
  </result>

In the above case, myUrl will be parsed against Ognl Value Stack and then URL encoded.

or when using the default parameter feature

  <result name="success" type="redirect">foo.jsp</result>

You should subclass this class if you're interested in adding more parameters or functionality to your Result. If you do subclass this class you will need to override doExecute(String, ActionInvocation).

Any custom result can be defined in struts.xml as:

  <result-types>
      ...
      <result-type name="myresult" class="com.foo.MyResult" />
  </result-types>

Please see the Result class for more info on Results in general.

See Also:
Result, Serialized Form

Field Summary
private static Log _log
           
static String DEFAULT_PARAM
          The default parameter
private  boolean encode
           
private  String lastFinalLocation
           
private  String location
           
private  boolean parse
           
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_PORTLET_CONTEXT
 
Constructor Summary
StrutsResultSupport()
           
StrutsResultSupport(String location)
           
StrutsResultSupport(String location, boolean parse, boolean encode)
           
 
Method Summary
protected  String conditionalParse(String param, ActionInvocation invocation)
          Parses the parameter for OGNL expressions against the valuestack
protected abstract  void doExecute(String finalLocation, ActionInvocation invocation)
          Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed).
 void execute(ActionInvocation invocation)
          Implementation of the execute method from the Result interface.
 String getLastFinalLocation()
          Returns the last parsed and encoded location value
 void setEncode(boolean encode)
          Set encode to true to indicate that the location should be url encoded.
 void setLocation(String location)
          The location to go to after action execution.
 void setParse(boolean parse)
          Set parse to true to indicate that the location should be parsed as an OGNL expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private static final Log _log

DEFAULT_PARAM

public static final String DEFAULT_PARAM
The default parameter

See Also:
Constant Field Values

parse

private boolean parse

encode

private boolean encode

location

private String location

lastFinalLocation

private String lastFinalLocation
Constructor Detail

StrutsResultSupport

public StrutsResultSupport()

StrutsResultSupport

public StrutsResultSupport(String location)

StrutsResultSupport

public StrutsResultSupport(String location,
                           boolean parse,
                           boolean encode)
Method Detail

setLocation

public void setLocation(String location)
The location to go to after action execution. This could be a JSP page or another action. The location can contain OGNL expressions which will be evaulated if the parse parameter is set to true.

Parameters:
location - the location to go to after action execution.
See Also:
setParse(boolean)

getLastFinalLocation

public String getLastFinalLocation()
Returns the last parsed and encoded location value


setParse

public void setParse(boolean parse)
Set parse to true to indicate that the location should be parsed as an OGNL expression. This is set to true by default.

Parameters:
parse - true if the location parameter is an OGNL expression, false otherwise.

setEncode

public void setEncode(boolean encode)
Set encode to true to indicate that the location should be url encoded. This is set to true by default

Parameters:
encode - true if the location parameter should be url encode, false otherwise.

execute

public void execute(ActionInvocation invocation)
             throws Exception
Implementation of the execute method from the Result interface. This will call the abstract method doExecute(String, ActionInvocation) after optionally evaluating the location as an OGNL evaluation.

Specified by:
execute in interface Result
Parameters:
invocation - the execution state of the action.
Throws:
Exception - if an error occurs while executing the result.

conditionalParse

protected String conditionalParse(String param,
                                  ActionInvocation invocation)
Parses the parameter for OGNL expressions against the valuestack

Parameters:
param - The parameter value
invocation - The action invocation instance
Returns:
The resulting string

doExecute

protected abstract void doExecute(String finalLocation,
                                  ActionInvocation invocation)
                           throws Exception
Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed). Subclasses must implement this class to handle custom logic for result handling.

Parameters:
finalLocation - the location (jsp page, action, etc) to go to.
invocation - the execution state of the action.
Throws:
Exception - if an error occurs while executing the result.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.