Versions Compared

Key

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

Update nomenclature

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.

Code Block
xml
xml
titleaction.xml

A result is a piece of code that is executed after your action has already completed and returned a value such as success or error. But WebWork comes with most of the result you'll need, for example: such as "servlet dispatcher," used for JSPs, and Velocity as well as alternative results such as FreeMarker and Jasper Reports (in PDF, XML, and HTML).

code
<action name="form03helloName2" class="lessonstutorial.Form03ActionHelloName2">
       <result name="success" type="dispatcher">page03>helloName2-success.jsp</result>
       <result name="error" type="dispatcher">page03>helloName-error.jsp</result>
     </action>

 

As you can see, that result configuration is made up of two parts: result mappings, which you've already seen associated with an action mapping, and result types.

Configuring result types

Every package in WebWork can be associated with one or more result types.

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.

code
Code Block
xml
xml
1action.xml
<xwork>
   <include name="webworkaction-default.xml"/>
   <package name="default" extends="webworkaction-default">

      <result-types>
        <result-type name="dispatcherimage" class="tutorial...ImageResult" default="true"/>
        <result-type name="redirect" class="..."/>
      </result-types>

      <default-interceptor-ref name="defaultStack"/>

      <action name="loginimage"
           class="org.hibernate.auction.web.actions.users.Logintutorial.ImageAction">
        <result name="input">login.jsp</result>
        <result name="success"
           type="redirectimage">/secure/dashboard.action</result>/>
     </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 xworkthe action.xml is through the use of global result mappings. Web applications often have a common set of results that are used across many actionsaction mappings. Common results include redirects to login actions and permission-denied pages. Rather than define each of these results in every action mapping, WebWork the framework lets you centralize the definitions for the common pages.

Code Block
<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>

...

Note
titleBe Careful

Because global reseults 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.

...