You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Overview

Results of an Action are used in Webwork to map to a view implementation(ex. jsp, vm, html) or another action. Keep in mind though, the com.opensymphony.xwork.Result interface 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.

<!-- xwork.xml  -->

<action name="bar" class="myPackage.barAction">
  <result name="success" type="dispatcher">
    <param name="location">foo.jsp</param>
  </result>
  <result name="error" type="dispatcher">
    <param name="location">error.jsp</param>
  </result>
</action>


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

dispatcher

com.opensymphony.webwork.dispatcher.ServletDispatcherResult

#Redirect

redirect

com.opensymphony.webwork.dispatcher.ServletRedirectResult

#Action Chaining

chain

com.opensymphony.xwork.ActionChainResult

#Velocity

velocity

com.opensymphony.webwork.dispatcher.VelocityResult

#FreeMarker

freemarker

com.opensymphony.webwork.views.freemarker.FreemarkerResult

#JasperReports

jasper

com.opensymphony.webwork.views.jasperreports.JasperReportsResult

#XML/XSL

xslt

com.opensymphony.webwork.views.xslt.XSLTResult

Results are specified in a xwork xml config file(xwork.xml) nested inside <action>. The location param is the default parameter, meaning you can specify the location two ways:

<action name="bar" class="myPackage.barAction">
  <result name="success" type="dispatcher">
    <param name="location">foo.jsp</param>
  </result>
</action>

or

<action name="bar" class="myPackage.barAction">
  <result name="success" type="dispatcher">foo.jsp</result>
</action>


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. See global-results

Dispatcher


Includes or forwards a view (usually a jsp)

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

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


Redirect


The response is told to redirect the browser to the specified location. The consequence of doing this means that the action that was just executed is lost or no longer available. This is because actions are built on a single-thread model.
NOTE: You may want to set the parse attribute to false so the location is not parsed for 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

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


Action Chaining


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.

<result name="success" type="chain">
    <param name="actionName">bar</param>
    <param name="namespace">/foo</param>
</result>

invokes this

<action name="bar" class="myPackage.barAction">
    ...
</action>


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

<result name="success" type="velocity">
    <param name="location">foo.vm</param>
</result>


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 "text/html" unless specified

<result name="success" type="freemarker">foo.ftl</result>


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

<result name="success" type="jasper">
    <param name="location">foo.jasper</param>
    <param name="dataSource">mySource</param>
    <param name="format">CSV</param>
</result>

or for pdf

<result name="success" type="jasper">
    <param name="location">foo.jasper</param>
    <param name="dataSource">mySource</param>
</result>


XML/XSL


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

<result name="success" type="xslt">foo.xslt</result>
  • No labels