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

Compare with Current View Page History

« Previous Version 9 Next »

After the Action processes the request, a result is selected to provide the response. A result may simply forward to a JavaServer Page, a FreeMaker, or Velocity template, or the result might construct a PDF or some other complex report. There may be multiple results available to an action mapping. To indicate which one to select, the Action returns the name of the appropriate result.

action.xml
<action name="helloName2" class="tutorial.HelloName2">
       <result name="success">helloName2-success.jsp</result>
       <result name="error">helloName-error.jsp</result>
     </action>

So far, our results have used the default type, Dispatcher. The Dispatcher forwards to another web resource. Other kinds of views can be used by specifying a different result type.

Configuring Result Types

The action-default package defines result types for the Results provided with the framework. If your package uses a custom result type, you can add it to your package.

types.

<xwork>
   <include name="action-default.xml"/>
   <package name="default" extends="action-default">

      <result-types>
        <result-type name="image" class="tutorial.ImageResult" />
      </result-types>

      <action name="image" class="tutorial.ImageAction">
        <result name="success" type="image"/>
     </action>
   </package>
</xwork>

Reducing Configuration Duplication with Global Result Mappings

It's not unusual for mappings to share Results. If your application is secured, then many mappings will need to return "login".

Another way to reduce the amount of configuration in the action.xml is through the use of global result mappings. Web applications often have a common set of results that are used across many action mappings. Common results include redirects to login actions and permission-denied pages. Rather than define each of these results in every action mapping, the framework lets you centralize the definitions for the common pages.

<package name="default" extends="webwork-default">
   <global-results>
      <result name="login"
         type="redirect">/login!default.action</result>
      <result name="unauthorized">/unauthorized.jsp</result>
   </global-results>
   <!-- other package declarations -->
</package>

Be Careful

Because global results are searched after local results, you can override any global result mapping by creating a local result mapping for a specific action. Recall that results can point to locations using relative or absolute paths. Because you may not know the context in which they're being invoked, it's best to use absolute paths for global results.

  • No labels