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:
translateVariables
methodNOTE: 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.1
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.
Result
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PARAM
The default parameter
|
static String |
DEFAULT_URL_ENCODING
use UTF-8 as this is the recommended encoding by W3C to avoid incompatibilities.
|
protected boolean |
parseLocation |
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
Constructor and Description |
---|
StrutsResultSupport() |
StrutsResultSupport(String location) |
StrutsResultSupport(String location,
boolean parse,
boolean encode) |
Modifier and Type | Method and Description |
---|---|
protected String |
conditionalParse(String param,
ActionInvocation invocation)
Parses the parameter for OGNL expressions against the valuestack
|
protected Collection<String> |
conditionalParseCollection(String param,
ActionInvocation invocation,
boolean excludeEmptyElements)
As
conditionalParse(String, ActionInvocation) but does not
convert found object into String. |
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
|
String |
getLocation()
Gets the location it was created with, mainly for testing
|
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.
|
public static final String DEFAULT_PARAM
public static final String DEFAULT_URL_ENCODING
protected boolean parseLocation
public StrutsResultSupport()
public StrutsResultSupport(String location)
public StrutsResultSupport(String location, boolean parse, boolean encode)
public void setLocation(String location)
location
- the location to go to after action execution.setParse(boolean)
public String getLocation()
public String getLastFinalLocation()
public void setParse(boolean parse)
parse
- true if the location parameter is an OGNL expression, false otherwise.public void setEncode(boolean encode)
encode
- true if the location parameter should be url encode, false otherwise.public void execute(ActionInvocation invocation) throws Exception
doExecute(String, ActionInvocation)
after optionally evaluating the
location as an OGNL evaluation.protected String conditionalParse(String param, ActionInvocation invocation)
param
- The parameter valueinvocation
- The action invocation instanceprotected Collection<String> conditionalParseCollection(String param, ActionInvocation invocation, boolean excludeEmptyElements)
conditionalParse(String, ActionInvocation)
but does not
convert found object into String. If found object is a collection it is
returned if found object is not a collection it is wrapped in one.param
- parameterinvocation
- action invocationexcludeEmptyElements
- 'true' for excluding empty elementsprotected abstract void doExecute(String finalLocation, ActionInvocation invocation) throws Exception
finalLocation
- the location (jsp page, action, etc) to go to.invocation
- the execution state of the action.Exception
- if an error occurs while executing the result.Copyright © 2000–2020 Apache Software Foundation. All rights reserved.