Versions Compared

Key

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

...

The

...

@Result

...

annotation

...

allows

...

the

...

definition

...

of

...

Action

...

results

...

in

...

the

...

Action

...

class

...

rather

...

than

...

an

...

XML

...

file.

Tip

The @Result annotation lives at the Action class level and not the method level. This matches what is found in an XML-based Action configuration. Do not be tempted to annotate your Action's methods; it will not work.

In order for @Result and @Results annotations to be configured correctly you must set the actionPackages filter init-param to a comma-separated list of packages containing the annotated Action classes. See Zero Configuration for further information; there are Action class naming conventions if you don't implement the Action interface and other tidbits there.

@Result Annotation Parameters

Wiki Markup


{tip}
The {{@Result}} annotation lives at the {{Action}} _class_ level and not the method level. This matches what is found in an XML-based {{Action}} configuration. *Do not be tempted to annotate your {{Action}}'s methods; it will not work.*
{tip}

In order for {{@Result}} and {{@Results}} annotations to be configured correctly you must set the {{actionPackages}} filter {{init-param}} to a comma-separated list of packages containing the annotated {{Action}} classes. See [Zero Configuration] for further information; there are {{Action}} class naming conventions if you don't implement the {{Action}} interface and other tidbits there.

h2. {{@Result}} Annotation Parameters

{float:right|width=300px}
  {info}
    See org.apache.struts2.config.Result annotation JavaDocs.
  {info}
{float}

* 
  • name

...

  • -

...

  • Result

...

  • name;

...

  • default

...

  • Action.SUCCESS

...

  • value

...

  • -

...

  • Value

...

  • of

...

  • result

...

  • (result

...

  • destination)

...

  • type

...

  • -

...

  • Type

...

  • of

...

  • result;

...

  • default

...

  • NullResult

...

  • .

...

  • For

...

  • example:

...

    • ServletRedirectResult
    • ServletActionRedirectResult - Equivalent to redirect-action

...

    • type

...

    • in

...

    • XML

...

    • config.

...

    • TilesResult
  • params - An Array of the parameters in the form {key1, value1, key2, value2}

@Result – Defining a Single Result

Map the "success" result (explicitly named) to a Tile definition named "/home.page".

{:=
Code Block
title
Defining
a
Single
Result
}
@Result(name="success", value="/home.page", type=TilesResult.class)
public class HomeAction extends ActionSupport {
    // ...
}

@Results – Defining Multiple Results

Defines a set of results for an Action.

Code Block
titleDefining Multiple Results
{code}

h2. {{@Results}} -- Defining Multiple Results

Defines a set of results for an {{Action}}.

{code:title=Defining Multiple Results}
@Results({
    @Result(name="success", value="/home.page", type=TilesResult.class),
    @Result(name="homeError", value="/homeError.page", type=tilesResult.class)
})
public class HomeAction extends ActionSupport {
    // ....
}
{code}

{dynamictasklist:Page Tasks}