Overview
Result Types are classes that determine what happens after an Action executes and a Result is returned. Developers are free to create their own Result Types according to the needs of their application or environment. In WebWork 2 for example, Servlet and Velocity Result Types have been created to handle rendering views in web applications.
...
Note: All built in webwork result types implement the
com.opensymphony.xwork.Result
...
interface,
...
which
...
represents
...
a
...
generic
...
interface
...
for
...
all
...
action
...
execution
...
results,
...
whether
...
that
...
be
...
displaying
...
a
...
webpage,
...
generating
...
an
...
email,
...
sending
...
a
...
JMS
...
message,
...
etc.
...
Result
...
types
...
define
...
classes
...
and
...
map
...
them
...
to
...
names
...
to
...
be
...
referred
...
in
...
the
...
action
...
configuration
...
results.
...
This
...
serves
...
as
...
a
...
shorthand
...
name-value
...
pair
...
for
...
these
...
classes.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
|
{code|title=snippet of
| |||||||
} ... <result-types> <result-type name="dispatcher" class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" default="true"/> <result-type name="redirect" class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/> <result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/> <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult"/> <result-type name="xslt" class="com.opensymphony.webwork.views.xslt.XSLTResult"/> <result-type name="jasper" class="com.opensymphony.webwork.views.jasperreports.JasperReportsResult"/> <result-type name="freemarker" class="com.opensymphony.webwork.views.freemarker.FreemarkerResult"/> <result-type name="httpheader" class="com.opensymphony.webwork.dispatcher.HttpHeaderResult"/> <result-type name="stream" class="com.opensymphony.webwork.dispatcher.StreamResult"/> </result-types> ... {code} {code|title=snippet of your |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
} <include file="webwork-default.xml"/> <package name="myPackage" extends="default"> <action name="bar" class="myPackage.barAction"> <!-- default result type is "dispatcher" --> <!-- default result name is "success" --> <result>foo.jsp</result> <result name="error">error.jsp</result> </result> </action> </package> {code} h2. Result Types Webwork provides several implementations of the {{ |
Result Types
Webwork provides several implementations of the com.opensymphony.xwork.Result
...
interface
...
to
...
make
...
web-based
...
interactions
...
with
...
your
...
actions
...
simple.
...
These
...
result
...
types
...
include:
...
Result |
---|
...
Type |
---|
...
name | class | |
---|---|---|
dispatcher | com.opensymphony.webwork.dispatcher.ServletDispatcherResult |
...
redirect | com.opensymphony.webwork.dispatcher.ServletRedirectResult |
...
chain | com.opensymphony.xwork.ActionChainResult |
...
velocity | com.opensymphony.webwork.dispatcher.VelocityResult |
...
freemarker | com.opensymphony.webwork.views.freemarker.FreemarkerResult |
...
jasper | com.opensymphony.webwork.views.jasperreports.JasperReportsResult |
...
xslt | com.opensymphony.webwork.views.xslt.XSLTResult |
...
header | com.opensymphony.webwork.dispatcher.HttpHeaderResult |
...
stream | com.opensymphony.webwork.dispatcher.StreamResult |
Results are specified in a xwork xml config file(xwork.xml)
...
nested
...
inside
...
<action>.
...
If
...
the
...
location
...
param
...
is
...
the
...
only
...
param
...
being
...
specified
...
in
...
the
...
result
...
tag,
...
you
...
can
...
simplify
...
it
...
as
...
follows:
Code Block | ||||
---|---|---|---|---|
| ||||
{code} <action name="bar" class="myPackage.barAction"> <result name="success" type="dispatcher"> <param name="location">foo.jsp</param> </result> </action> {code} |
or
...
simplified
Code Block | ||||
---|---|---|---|---|
| ||||
{code} <action name="bar" class="myPackage.barAction"> <result name="success" type="dispatcher">foo.jsp</result> </action> {code} +NOTE:+ The Parse attribute enables the location element to be parsed for expressions. An example of how this could be useful |
if you are extending webwork-default.xml, then the default result type is "dispatcher". Also, if you don't specify the name of a result, it is assumed to be "success". This means you can simply the result down to
Code Block | ||||
---|---|---|---|---|
| ||||
<action name="bar" class="myPackage.barAction">
<result>foo.jsp</result>
</action>
|
NOTE: The Parse attribute enables the location element to be parsed for expressions. An example of how this could be useful:
Code Block |
---|
: {code} <result name="success" type="redirect">/displayCart.action?userId=${userId}</result> {code} + |
NOTE:
...
You
...
can
...
also
...
specify
...
global-results
...
to
...
use
...
with
...
multiple
...
actions.
...
This
...
can
...
save
...
time
...
from
...
having
...
to
...
add
...
the
...
same
...
result
...
to
...
many
...
different
...
actions.
...
For
...
more
...
information
...
on
...
result
...
tags
...
and
...
global-results,
...
see
...
...
section.
Dispatcher
Anchor | ||||
---|---|---|---|---|
|
Includes or forwards to a view (usually a jsp). Behind the scenes WebWork will use a RequestDispatcher, where the target servlet/JSP receives the same request/response objects as the original servlet/JSP. Therefore, you can pass data between them using request.setAttribute() – the WebWork action is available.
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution (ex. jsp) |
parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions |
Code Block |
---|
h4. Dispatcher {anchor:Dispatcher} Includes or forwards to a view (usually a jsp). Behind the scenes WebWork will use a RequestDispatcher, where the target servlet/JSP receives the same request/response objects as the original servlet/JSP. Therefore, you can pass data between them using request.setAttribute() -- the WebWork action is available. ||Parameters || Required || Description || | location | *yes* | the location to go to after execution (ex. jsp) | | parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions | {code} <result name="success" type="dispatcher"> <param name="location">foo.jsp</param> </result> {code} h4. Redirect {anchor:Redirect} The response is told to redirect the browser to the specified location (a new request from the client). The consequence of doing this means that the action (action instance, action errors, field errors, etc) that was just executed is lost and no longer available. This is because actions are built on a single-thread model. The only way to pass data is through the session or with web parameters |
Redirect
Anchor | ||||
---|---|---|---|---|
|
The response is told to redirect the browser to the specified location (a new request from the client). The consequence of doing this means that the action (action instance, action errors, field errors, etc) that was just executed is lost and no longer available. This is because actions are built on a single-thread model. The only way to pass data is through the session or with web parameters (url?name=value)
...
which
...
can
...
be
...
OGNL
...
expressions.
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution |
parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions |
Code Block |
---|
||Parameters || Required || Description || | location | *yes* | the location to go to after execution | | parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions | {code} <result name="success" type="redirect"> <param name="location">foo.jsp</param> <param name="parse">false</param> </result> {code} h4. Action Chaining {anchor:Action Chaining} A special kind of view that invokes |
Action Chaining
Anchor | ||||
---|---|---|---|---|
|
A special kind of view that invokes GenericDispatch (using the previously existing ActionContext) and executes another action. This is useful if you need to execute one action immediately after another.
Parameters | Required | Description |
---|---|---|
actionName | yes | the name of the action that will be chained to |
namespace | no | sets the namespace of the Action that we're chaining to. If namespace is null, this defaults to the current namespace. |
Code Block |
---|
GenericDispatch (using the previously existing ActionContext) and executes another action. This is useful if you need to execute one action immediately after another. ||Parameters || Required || Description || | actionName | *yes* | the name of the action that will be chained to | namespace | no | sets the namespace of the Action that we're chaining to. If namespace is null, this defaults to the current namespace. | {code} <result name="success" type="chain"> <param name="actionName">bar</param> <param name="namespace">/foo</param> </result> {code} |
invokes
...
this
Code Block |
---|
} <action name="bar" class="myPackage.barAction"> ... </action> {code} h4. Velocity |
Velocity
Anchor | ||||
---|---|---|---|---|
|
This result mocks a JSP execution environment and then displays a Velocity template that will be streamed directly to the servlet output.
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution |
parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions |
Code Block |
---|
{anchor:Velocity} This result mocks a JSP execution environment and then displays a Velocity template that will be streamed directly to the servlet output. ||Parameters || Required || Description || | location | *yes* | the location to go to after execution | | parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions | {code} <result name="success" type="velocity"> <param name="location">foo.vm</param> </result> {code} h4. FreeMarker {anchor:FreeMarker} ||Parameters || Required || Description || | location | *yes*| the location to go to after execution | | parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions | | contentType | no | defaults to |
FreeMarker
Anchor | ||||
---|---|---|---|---|
|
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution |
parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions |
contentType | no | defaults to "text/html" |
...
unless |
...
specified |
Code Block |
---|
| {code} <result name="success" type="freemarker">foo.ftl</result> {code} h4. |
JasperReports
Anchor | ||||
---|---|---|---|---|
|
Generates a JasperReports report using the specified format or PDF if no format is specified.
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution |
parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions |
dataSource | yes | the Ognl expression used to retrieve the datasource from the value stack (usually a List) |
format | no | the format in which the report should be generated, defaults to pdf |
contentDisposition | no | defaults to "inline" when using documentName unless specified |
documentName | no | generates the http header "Content-disposition = <contentDisposition>; filename=<documentName>.<format>" |
Code Block |
---|
JasperReports {anchor:JasperReports} Generates a JasperReports report using the specified format or PDF if no format is specified. ||Parameters || Required || Description || | location | *yes* | the location to go to after execution | | parse | no | true by default. If set to false, the location param will not be parsed for Ognl expressions | | dataSource | *yes* | the Ognl expression used to retrieve the datasource from the value stack (usually a List) | | format | no |the format in which the report should be generated, defaults to pdf | | contentDisposition | no | defaults to "inline" when using documentName unless specified | | documentName | no | generates the http header "Content-disposition = <contentDisposition>; filename=<documentName>.<format>" | {code} <result name="success" type="jasper"> <param name="location">foo.jasper</param> <param name="dataSource">mySource</param> <param name="format">CSV</param> </result> {code} |
or
...
for
...
Code Block |
---|
} <result name="success" type="jasper"> <param name="location">foo.jasper</param> <param name="dataSource">mySource</param> </result> {code} h4. |
XML/XSL
...
Anchor | ||||
---|---|---|---|---|
|
...
Interfaces
...
with
...
xml
...
transformations.
Parameters | Required | Description |
---|---|---|
location | yes | the location to go to after execution |
parse | no | Defaults to false. If set to true, the location will be parsed for Ognl expressions |
Code Block |
---|
||Parameters || Required || Description ||
| location | *yes* | the location to go to after execution |
| parse | no | Defaults to false. If set to true, the location will be parsed for Ognl expressions |
{code}
<result name="success" type="xslt">foo.xslt</result>
|
HttpHeader
Anchor | ||||
---|---|---|---|---|
|
A custom Result type for evaluating HTTP headers against the ValueStack.
Parameters | Required | Description |
---|---|---|
status | no | the http servlet response status code that should be set on a response |
parse | no | true by default. If set to false, the headers param will not be parsed for Ognl expressions |
headers | no | header values |
Example:
Code Block | ||||
---|---|---|---|---|
| ||||
{code} h4. HttpHeader {anchor:HttpHeader} A custom Result type for evaluating HTTP headers against the ValueStack. ||Parameters || Required || Description || | status | no | the http servlet response status code that should be set on a response | | parse | no | true by default. If set to false, the *headers* param will not be parsed for Ognl expressions | | headers| no | header values| Example: {code:xml} <result name="success" type="header"> <param name="status">204</param> <param name="headers.a">a custom header value</param> <param name="headers.b">another custom header value</param> </result> {code} |