struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McGrady <m...@michaelmcgrady.com>
Subject Re: Capturing Previous Action Request
Date Sun, 01 Feb 2004 23:04:16 GMT
Sorry, David, I did not clean up that code.  Here is a cleaner version to 
think on:

public interface Command {}
public interface Do extends Command {}
public final class Redo implements Command {}
public final class Undo implements Command {}
public class UndoableList {
   private int       maxHistory = 100;
   private LinkedList   history = new LinkedList();
   private LinkedList  redoList = new LinkedList();
   private UndoableList() {
   }
   public static UndoableList getInstance() {
   return new UndoableList();
   }
   public void setMaxHistory(int maxHistory) {
     this.maxHistory = maxHistory;
   }
   public void invoke(Command command) {
     if (command instanceof Undo) { undo(); return; }
     if (command instanceof Redo) { redo(); return; }
     if (command instanceof Do) {
       addToHistory(command);
     } else {
       history.clear();
     }
     if (redoList.size() > 0) {
       redoList.clear();
     }
   }
   private void undo() {
     if (history.size() > 0) {
       Command undoCommand;
       undoCommand = (Command)history.removeFirst();
       redoList.addFirst(undoCommand);
     }
   }
   private void redo() {
     if (redoList.size() > 0) {
       Command redoCommand;
       redoCommand = (Command)redoList.removeFirst();
       history.addFirst(redoCommand);
     }
   }
   private void addToHistory(Command command) {
     history.addFirst(command);
     if (history.size() > maxHistory) {
       history.removeLast();
     }
   }
}

At 01:57 PM 2/1/2004, David Liles wrote:
>I am working on a work-flow web app and need to provide the user with the 
>ability to navigate back to their previous page by the use of a "back" 
>button within the web app.... not the browser's back button.
>
>How can I capture the action mapping that was processed in order to allow 
>the user to navigate back?
>
>Thanks,
>
>Dave

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message