Versions Compared

Key

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

Move some content to Result Types

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.

When an Action method completes, it returns a String. The value of the String is used to select a result element. An action will often have a set of results representing different possible outcomes. A standard set of result tokens are defined by the Action interface.

...

Result Elements

The result element as has two jobs. First, it provides a logical name for the result. An Action can pass back a token like "success" or "error" without knowing any other implementation detaildetails. Second, the result element provides a Result Type. Most results simply forward to a server page or template, but other Result Types can be used to do more interesting things.

...

Using these intelligent defaults, the most often used result types also become the simplest.

Code Block
xml
xml
:titleResult element without defaults
<result name="success" type="dispatcher">
    <param name="location">/thank_you.jsp</param>
</result>
Code Block
xml
xml
:titleA Result element using some defaults
<result>
    <param name="location">/thank_you.jsp</param>
</result>

The param tag sets a property on the Result object. The most commonly-set property is location, which usually specifies the path to a web resources. The param attribute is another intelligent default.

Code Block
xml
xml
:titleResult element using more defaults
<result>/thank_you.jsp</result>

Mixing results with intelligent defaults with other results makes it easier to see the "critical path".

Code Block
xml
xml
:titleMultiple Results
<action name="Hello">
  <result>/pages/Hello/Result.jsp</result>
  <result name="error">/pages/Hello/Error.jsp</result>
  <result name="input">/pages/Hello/Input.jsp</result>
</action>

...

Most often, results are nested with the action element. But some results apply to multiple actions. In a secure application, a client might try to access a page without being authorized, and many action actions may need access to a "logon" result.

If actions need to share results, a set of global results can be defined for each package. The framework will first look for a local result nested in the action. If a local match is not found, then the global results are checked.

Code Block
xml
xml
titleDefining global results
<global-results>
  <result name="error">/pages/Error.jsp</result>
  <result name="invalid.token">/pages/Error.jsp</result>
  <result name="login" type="redirect-action">Logon!input</result>
</global-results>

...