Versions Compared

Key

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

Add summary

After the Action processes the request, a result is selected to provide the response. A result may simply forward to a HTML page, or a JavaServer Pagepage, 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 class returns the a name of corresponding to the appropriate result.

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

...

Code Block
xml
xml
titleaction.xml
<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

...

Results

It's not unusual for mappings to share Results. If a need for the same result. For example, if your application is secured, then many mappings will might 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 pagesif the security check fails. Rather than define each of these results a common result in every action mapping, the framework lets you centralize the definitions for the common pagesdefine global results.

Code Block
xml
xml
titleaction.xml
<package name="default" extends="webwork-default">
   <global-results>
      <result name="login"
         type="redirect">/login!default.action<-action">login</result>
      <result name="unauthorized">/unauthorized.jsp</result>
   </global-results>
   <!-- other package declarations -->
</package>
Note
titleBe CarefulGlobal Absolutes

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 . Results can indicate resources using relative or absolute pathsURIs. Because you may not know the context in which they're a result is being invoked, it's best to use absolute paths for global results.

Summary

The framework offers a variety of result types. An Action can select the appropriate result by name, without actually knowing what result type will be rendered. If a result is needed by multiple action mappings, it can be defined once as a global result.

Next

Onward to Understanding Interceptors

Prev

Return to Understanding Actions