Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Update formatting and nomenclature

Most use cases can be divided into two phases. First, we need to change or query the application's state, and then we need to present an updated view of the application. The Action class manages the application's state, and the Result Type manages the view.

Predefined

See Result Configuration for basic information about how results are configuration.

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 the framework, for example, Servlet and Velocity Result Types have been created to handle rendering views in web applications.

(warning) Note: All built in 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, and so forth.

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.

...


...
<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-type name="plaintext" class="com.opensymphony.webwork.dispatcher.PlainTextResult" />
</result-types>
...

...


<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>

Result Types

The framework provides several implementations of the com.opensymphony.xwork.Result interface to make web-based interactions with your actions simple. These result types include:, ready to use in your own applications.

Chain Result

Used for Action Chaining

Dispatcher Result

Used for JSP integration

FreeMarker Result

Used for FreeMarker integration

HttpHeader Result

Used to control special HTTP behaviors JasperReports Result

Used for JasperReports integration

Redirect Result

Used to redirect to another URL

Redirect Action Result

Used to redirect to another Action

Stream Result

Used to stream an InputStream back to the browser (usually for file downloads)

Velocity Result

Used for Velocity integration

XSL Result

Used for XML/XSLT integration

PlainText Result

Used to display the raw content of a particular page (i.e jsp, HTML)

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:

...


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

JasperReports Result

Used for JasperReports integration

Optional, third-party plugin

Additional Result Types can be created and plugged into an application by implementing the com.opensymphony.xwork.Result interface. Custom Result Types might include generating an email or JMS message, generating images, and so forth.

Registering Result Types

All Result Types are plugged in via the

or simplified

...


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

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

...


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

(warning) Note: The Parse attribute enables the location element to be parsed for expressions. An example of how this could be useful:

...


<result name="success" type="redirect">/displayCart.action?userId=${userId}</result>

(warning) 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.
(lightbulb) For more information on result tags and global-results, see Result Configuration.