WebObjects 5.4.2

com.webobjects.appserver
Class WODirectAction

java.lang.Object
  extended by com.webobjects.appserver.WOAction
      extended by com.webobjects.appserver.WODirectAction
All Implemented Interfaces:
NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions, NSValidation
Direct Known Subclasses:
D2WActions, WOAdminAction, WOEventDisplay, WOEventSetup, WOProjectBuilderAction, WOStats

public class WODirectAction
extends WOAction
implements NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions, NSValidation

WODirectAction is an abstract class that defines the interface for direct action classes. You subclass WODirectAction to provide an object that is a repository for action methods.

WODirectAction provides the simplest interface for adding logic and custom code to your WebObjects application. WODirectAction objects are instantiated when a URL requested by a client browser is sent to the WebObjects application. The WODirectActionRequestHandler determines the proper class and action to be invoked and then passes control to the WODirectAction subclass.

In contrast to a WOComponent-based action, a direct action is well-defined by the URL that invokes it. For example, the following URL will invoke the method findEmployeeAction on the subclass of WODirectAction called Common:

http://localhost/cgi-bin/WebObjects/Myapp.woa/wa/Common/findEmployee

A subclass of WODirectAction is a repository for action methods. New WebObjects applications contain a default implementation of WODirectAction subclass called DirectAction. The DirectAction class is used when no class is specified in the URL.

In summary, here are some URLs and actions they invoke:

This URL... Invokes this method...
.../MyApp.woa/wa/ defaultAction on class DirectAction
.../MyApp.woa/wa/find findAction on class DirectAction, if it exists, or defaultAction on class find otherwise
.../MyApp.woa/wa/find/ same as .../MyApp.woa/wa/find
.../MyApp.woa/wa/Common/find findAction on class Common
.../MyApp.woa/wa/Common/ CommonAction on class DirectAction, if it exists, or defaultAction on class Common otherwise

WODirectActionRequestHandler only invokes methods on subclasses of WODirectAction. If the specified class or action doesn't exist, WODirectActionRequestHandler throws an exception.

To handle stale session IDs (e.g. session IDs stored in cookies, and those session IDs refer to expired sessions), make sure to do the following at the beginning of your direct action method:

public WOActionResults myAction() { if ( getSessionIDForRequest(request()) != null && existingSession() == null ) { // special behavior, like a returning a login page, e.g. return pageWithName("LoginPage"); } else { // whatever else you'd normally do here } }


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSValidation
NSValidation.DefaultImplementation, NSValidation.Utility, NSValidation.ValidationException
 
Field Summary
static String actionText
          String at the end of the WODirectAction name (i.e fetchMovieAction the actionText value is 'Action')
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
KeyPathSeparator
 
Constructor Summary
WODirectAction(WORequest aRequest)
          Subclasses must override to provide any additional initialization.
 
Method Summary
 WOActionResults defaultAction()
          Returns a WOActionResults object that is the result of sending generateResponse() to the page named "Main".
 String getSessionIDForRequest(WORequest aRequest)
          Returns the session ID, or null if one does not exist.
 WOActionResults performActionNamed(String anActionName)
          Performs the action with the specified name and returns the result of that action.
 void takeFormValueArraysForKeyArray(NSArray aKeyArray)
          Performs takeValueForKey on each key in aKeyArray using values from the receiver's request.
 void takeFormValuesForKeyArray(NSArray aKeyArray)
          Performs takeValueForKey on the each key in aKeyArray using values from the receiver's request.
 
Methods inherited from class com.webobjects.appserver.WOAction
canAccessFieldsDirectly, context, debugString, existingSession, handleQueryWithUnboundKey, handleTakeValueForUnboundKey, initializeRequestSessionIDInContext, languages, logString, pageWithName, request, session, setLanguages, takeValueForKey, takeValueForKeyPath, toString, unableToSetNullForKey, validateTakeValueForKeyPath, validateValueForKey, valueForKey, valueForKeyPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding
takeValueForKey, valueForKey
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling
handleQueryWithUnboundKey, handleTakeValueForUnboundKey, unableToSetNullForKey
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
takeValueForKeyPath, valueForKeyPath
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding
takeValueForKey, valueForKey
 
Methods inherited from interface com.webobjects.foundation.NSValidation
validateTakeValueForKeyPath, validateValueForKey
 

Field Detail

actionText

public static final String actionText
String at the end of the WODirectAction name (i.e fetchMovieAction the actionText value is 'Action')

See Also:
Constant Field Values
Constructor Detail

WODirectAction

public WODirectAction(WORequest aRequest)
Subclasses must override to provide any additional initialization.

Parameters:
aRequest - the request to be processed
Method Detail

getSessionIDForRequest

public String getSessionIDForRequest(WORequest aRequest)
Returns the session ID, or null if one does not exist. Searchs for aRequest's session ID, first in the form values, then in the cookies.

Specified by:
getSessionIDForRequest in class WOAction
Parameters:
aRequest - the request being handled
Returns:
the session ID for the request, or null

defaultAction

public WOActionResults defaultAction()
Returns a WOActionResults object that is the result of sending generateResponse() to the page named "Main".

Returns:
a WOActionResults containing the generated response.

performActionNamed

public WOActionResults performActionNamed(String anActionName)
Performs the action with the specified name and returns the result of that action. The default implementation appends "Action" to anActionName and tries to invoke the resulting method name. Override this method to change how actions are dispatched.

Specified by:
performActionNamed in class WOAction
Parameters:
anActionName - name of the action
Returns:
a WOActionResults containing the result of the direct action

takeFormValueArraysForKeyArray

public void takeFormValueArraysForKeyArray(NSArray aKeyArray)
Performs takeValueForKey on each key in aKeyArray using values from the receiver's request.

This method uses an NSArray for each form value. This is useful when a user can select multiple items for a form value, such as a WOBrowser. If a form value contains only one item, this method uses an NSArray with one object. To use single objects as form values use takeFormValuesForKeyArray.

Parameters:
aKeyArray - an array of keys
See Also:
WOAction.takeValueForKey(Object value, String key), WODirectAction.takeFormValuesForKeyArray(NSArray aKeyArray)

takeFormValuesForKeyArray

public void takeFormValuesForKeyArray(NSArray aKeyArray)
Performs takeValueForKey on the each key in aKeyArray using values from the receiver's request. This method uses an a single object for each form value. If a form value contains more than one item, such as a WOBrowser, this method uses the first item in the array. To use arrays of objects as form values, use takeFormValueArraysForKeyArray.

Parameters:
aKeyArray - an array of keys
See Also:
WOAction.takeValueForKey(Object value, String key), WODirectAction.takeFormValueArraysForKeyArray(NSArray aKeyArray)

Last updated June 2008

Copyright © 2000-2008 Apple Inc.