Result represents the 'receiver' in a command pattern. It might be used to generate a response for a webapp, render ui for a Swing base app, execute a batch update etc.

Code

XWork2 result should extends off Result interface. The custom result could have paremeter injected into it from xwork.xml file as well, just be sure to have getter / setters for those parameters.

The parameter needs to be String, however one could write up a Abstract result which allows syntax like ${...} to be evaluated against XWork2 Ognl Value Stack. StrutsResultSupport does that actually. In order to help out with that, XWork2 have an utility class called TextParseUtil that does that parsing functionality.

public class MyResult implements Result {
    // let's have getter/setter for our 'injectable' paremeter.
    private String myParam;
    public String getMyParam() { return this.myParam; }
    public void setMyParam(String myParam) { this.myParam = myParam; }

    ....
    public void execute(ActionInvocation invocation) throws Exception {
        ....
    }
    ....
  }

and registered it in xwork.xml before using it

<xwork>
   <package name="myPackage" ...>
      <!-- registre our custom result -->
      <result-types>
        <result-type name="myResult" class="foo.bar.MyResult">
          <param name="myParam">some param value</param>
        </result>
      <result-types>

      <action ....>
         <!-- Now we could use it -->
         <result type="myResult" ...>
            ....
         </result>
      </action>
   </package>
 </xwork>

Default result types

<result-types>
    <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
</result-types>