You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Guillermo Meyer <gm...@sib.interbanking.com.ar> on 2003/12/24 12:10:33 UTC

Navigation Stack

Hi:
I'm working with a Struts 1.0 application. I extended Action to create a
base action that handles backwards navigation in a stack fashion.
Each method calls a "saveStep" method to the stack. This step has form,
mapping and dispatch name. Base action has a method called "stepBack"
that can be called from the browser by clicking the "back" button (not
browser back button, but a submit button). This stepBack method executes
the last step in the stack and goes backwards. Another features exists
like checkPoint step, and an undoStep to return from a validation in
Validator Form.

	public ActionForward stepBack(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
          throws Exception {
		NavigationStack ns =
this.retrieveNavigationStack(request);
		synchronized(ns) {
			//if not reloading
			StackStep ss = null;
			if(this.isTokenValid(request)) {
                try {
			  ns.pop(); //last step, ignore it.
                    ss = ns.pop();
                } catch (Exception e){
                   return this.handleEmptyStack(mapping, form, request,
response);
                }
			} else {
				ss = ns.getLastPopped();
			}
			return ss.process(request, response);
		}
	}

	public void saveStep(ActionMapping mapping, ActionForm form,
HttpServletRequest req, String dispatchName, boolean isCheckPoint) {
		//si no se indicó invalidar el grabado...
		if(this.isStepValid(req)) {
			NavigationStack ns =
this.retrieveNavigationStack(req);
			synchronized(ns) {
				StackStep newStep = new
StackStep(dispatchName, mapping, form, isCheckPoint);
				newStep.setServlet(this.getServlet());
				//lo apila siempre y cuando sean
distintos (el último y el nuevo)
				if(!newStep.equals(ns.getLast())) {
					ns.push(newStep);
				}
				this.saveNavigationStack(req, ns);
			}
		}
	}


I would like to know what you thing about this kind of navigation
management and know how are you dealing with this problem. With this
solution I can link 2 use case action (I designed one action for each
use case) and click back button to return wherever i was called.

Thanks in advance.

Guillermo Meyer
System Engineer.
EDS Argentina.

RE: Navigation Stack

Posted by Andrew Hill <an...@gridnode.com>.
Im working with struts1.1 myself.

Our application has quite a few screens that correspond to records in the
application, and these records are often related to other records in the
application - ie you might need to pick one from a drop down or such like.
We were able to give the user the ability to create (or edit) a record
related to the current screens record, and when finished come back to the
current screen (to select the newly created record) and keep working with
all fields entered so far preserved but without the record yet being saved.
This is allowed to any depth. (Our app can be quite complex to configure so
this also helps guide the user through all the records that need to be
configured for something (can be quite a few for something like configuring
the app to use a certain RosettaNet PIP with a certain partner or such like
stuff) - thus making it a sort of navigation stack ).

It works by using a stack of what I term "Operation Context" objects - in
that each element in the stack contains info related to the context of a
particular operation (ie : edit a type X record, etc...). The Operation
Contexts may be stacked, so if during editing a type X record the user
realises they need to create a type Y record for X to refer to they can go
off and do it, and when that operation is complete they will be brought back
to the screen for the X record...

Ive modified RequestProcessor so it will look for session scoped actionforms
in the operation context rather than the session if there is an operation
context associated with this request (managed by url rewriting to keep track
of the OpCons unique id). This has the added advantage of allowing me to
have several windows all working with the same record type (ie: same action
and type of action form) where the form is session scoped, without them
interfering with each other as would be the normal case with session scoped
action forms.

-----Original Message-----
From: Guillermo Meyer [mailto:gmeyer@sib.interbanking.com.ar]
Sent: Wednesday, 24 December 2003 19:11
To: Struts Users Mailing List
Subject: Navigation Stack


Hi:
I'm working with a Struts 1.0 application. I extended Action to create a
base action that handles backwards navigation in a stack fashion.
Each method calls a "saveStep" method to the stack. This step has form,
mapping and dispatch name. Base action has a method called "stepBack"
that can be called from the browser by clicking the "back" button (not
browser back button, but a submit button). This stepBack method executes
the last step in the stack and goes backwards. Another features exists
like checkPoint step, and an undoStep to return from a validation in
Validator Form.

	public ActionForward stepBack(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
          throws Exception {
		NavigationStack ns =
this.retrieveNavigationStack(request);
		synchronized(ns) {
			//if not reloading
			StackStep ss = null;
			if(this.isTokenValid(request)) {
                try {
			  ns.pop(); //last step, ignore it.
                    ss = ns.pop();
                } catch (Exception e){
                   return this.handleEmptyStack(mapping, form, request,
response);
                }
			} else {
				ss = ns.getLastPopped();
			}
			return ss.process(request, response);
		}
	}

	public void saveStep(ActionMapping mapping, ActionForm form,
HttpServletRequest req, String dispatchName, boolean isCheckPoint) {
		//si no se indicó invalidar el grabado...
		if(this.isStepValid(req)) {
			NavigationStack ns =
this.retrieveNavigationStack(req);
			synchronized(ns) {
				StackStep newStep = new
StackStep(dispatchName, mapping, form, isCheckPoint);
				newStep.setServlet(this.getServlet());
				//lo apila siempre y cuando sean
distintos (el último y el nuevo)
				if(!newStep.equals(ns.getLast())) {
					ns.push(newStep);
				}
				this.saveNavigationStack(req, ns);
			}
		}
	}


I would like to know what you thing about this kind of navigation
management and know how are you dealing with this problem. With this
solution I can link 2 use case action (I designed one action for each
use case) and click back button to return wherever i was called.

Thanks in advance.

Guillermo Meyer
System Engineer.
EDS Argentina.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org