live.struts.actions
Class SwitchedAction

java.lang.Object
  extended byorg.apache.struts.action.Action
      extended bylive.struts.actions.CheckedAction
          extended bylive.struts.actions.SwitchedAction
Direct Known Subclasses:
ActivateGroupAction, ActivateGuestAction, ChangeAGuestsGroupAction, ChangeMemoryAction, ChangeNetworkMembers, ChangePassword, ChangeSharedStorageMembers, ChMinidisks, CloneGuestAction, DeactivateGroupAction, DeactivateGuestAction, DeleteGroupAction, DeleteGuestAction, DeleteNetworkAction, DeleteSharedMemAction, NewGroupAction, NewGuestAction, NewNetworkAction, NewSharedMemAction

public abstract class SwitchedAction
extends CheckedAction

This is another sort of "convienience base class" that replaces a fairly common process. There are a number of actions the user can take that require both a page to be displayed to get some information then to actually carry out the action. For instance, when creating a network, an action is needed to get the list of guests on the server so the user can select what guests to add, then another action is needed to do the actual addition. As another example, deleting a guest displays a confirmation page before deleting. In order to reduce the proliferation of Actions, things such as these are combined into one Action class which contains a method for each. The sever decides which function to run based on whether the request was GETed or POSTed. In the former case, the Action should simply gather any information necessary and display the page to the user; in the latter, it should actually carry out the request. This class takes care of the determination of which method was used in the request and calling the appropriate method. So an example with delete guest works as follows:

  1. The user, from the individual guest page, clicks delete
  2. The DeleteGuestAction action (a subclass of this) is called, act(CheckedAction.ActionInfo) determines that it was submitted using GET and calls displayPage(CheckedAction.ActionInfo).
  3. DeleteGuestAction.displayPage(CheckedAction.ActionInfo) sets some attributes indicating what the user is doing and forwards to the generic confirmation page, which is displayed to the user.
  4. When the user clicks on the "yes, I want to delete who-and-who" link, the confirmation page POSTs to the same URL it came from. This calls this Action again, but this time act figures out that it was a POST request, so calls performAction(CheckedAction.ActionInfo).
  5. DeleteGuestAction.displayPage(CheckedAction.ActionInfo) then actually deletes the guest.
  6. Author:
    Evan Driscoll

    Nested Class Summary
     
    Nested classes inherited from class live.struts.actions.CheckedAction
    CheckedAction.ActionInfo
     
    Field Summary
     
    Fields inherited from class org.apache.struts.action.Action
    defaultLocale, servlet
     
    Constructor Summary
    SwitchedAction()
               
     
    Method Summary
     org.apache.struts.action.ActionForward act(CheckedAction.ActionInfo info)
              act is final so that subclasses don't override it by mistake and break things.
    abstract  org.apache.struts.action.ActionForward displayPage(CheckedAction.ActionInfo info)
              This function is called when a request was submitted by an HTTP GET request.
    abstract  org.apache.struts.action.ActionForward performAction(CheckedAction.ActionInfo info)
              This function is called when a request was submitted by an HTTP POST request.
     
    Methods inherited from class live.struts.actions.CheckedAction
    execute
     
    Methods inherited from class org.apache.struts.action.Action
    addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    SwitchedAction

    public SwitchedAction()
    Method Detail

    act

    public final org.apache.struts.action.ActionForward act(CheckedAction.ActionInfo info)
    act is final so that subclasses don't override it by mistake and break things.

    Specified by:
    act in class CheckedAction
    Parameters:
    info - Holds the parameters that were passed to execute, plus things like the cache and threads info deduced from those parameters
    Returns:
    An object that implements getForward
    See Also:
    CheckedAction.act(live.struts.actions.CheckedAction.ActionInfo)

    displayPage

    public abstract org.apache.struts.action.ActionForward displayPage(CheckedAction.ActionInfo info)
    This function is called when a request was submitted by an HTTP GET request. Implement this in subclasses to display a page where the user can enter any information necessary to actually do something, confirm that they want to actually do something, etc.

    Parameters:
    info - The request info passed to act(CheckedAction.ActionInfo)
    Returns:
    The forward to go to

    performAction

    public abstract org.apache.struts.action.ActionForward performAction(CheckedAction.ActionInfo info)
    This function is called when a request was submitted by an HTTP POST request. This function should actually perform whatever action the user wanted. You should probably strive to make it so that the URL that calls this action can only be POSTed to from the page displayed by displayPage(CheckedAction.ActionInfo) so that you know that the user is coming from that page.

    Parameters:
    info - The request info passed to act(CheckedAction.ActionInfo)
    Returns:
    The forward to go to


    Copyright © 2005