PDA

View Full Version : Menus



Graham
Jul 28th, 2005, 03:15 AM
Hi,

I am currently looking at refactoring an existing application to use Webflow. The current application consists of 12 Struts Modules - each module consisting of between 2 an 30 screens. In Webflow speak each module would map to a <subflow-state>. The maintenance of the system is becoming more and more difficult because of complex conditional navigation flows, so I am looking at Webflow as a way to externalise into xml the navigation of the application.

One of the requirements for the application is the ability to go back to a completed module and recommence the flow from this point. At present the application handles this via a menu of the left side of the screen with hyperlinks to the relevant Struts ".do" action. Is there any way in the Webflow framework to perform an equivalent action?

I basically think I would like to be able to setup a menu with actions which execute a "stateId" rather than an "eventId".


<a href="navigate.htm?_stateId=addressDetails&_flowExecutionId=... />


Graham

klr8
Jul 28th, 2005, 10:49 AM
Typically, I would say that a 'menu' is not really a use case for SWF since it involves free browsing: you're jumping around, which is different from a 'controlled navigation'.

However, each of those modules you mention could still be a seperate web flow (possibly with subflows). Check the flowlauncher sample application for an illustration of a number of different ways to launch flows.


One of the requirements for the application is the ability to go back to a completed module and recommence the flow from this point.

Could you clarify that a bit? Is the entire application one big flow that spans several modules? Or does the app consist of several individual flows (modules), and you need to jump into the middle of an ongoing one?

Erwin

Graham
Jul 28th, 2005, 06:18 PM
It is really one big application which spans several modules.

While the application has a menu, it acts more like a progress indicator and breadcrumbs. As the user progress through the modules, the menu indicates which module they are filling out, has links back to modules they have previously completed, and displays modules they have yet to complete (these are not links).

I had a look at the flow launcher example, and I don't think it is what I am looking for. What I want is the ability to step back to a point in the flow, not launch a new flow.

klr8
Jul 29th, 2005, 12:33 AM
I see. In this case an overarching main flow that manages progress between all the modules would make sense. It would ofcourse spawn each of the modules using a subflow-state.

Stepping back is basically easy ofcourse: just provide transitions in your flow to make that possible, maybe hitting an action state at the beginning of each flow that figures out what the progress in that particular module is and jumps to the correct point.

Erwin

Graham
Jul 31st, 2005, 10:43 PM
Ok, I think I worked out the code to do this.

As suggested, the main flow has a new action state:



<action-state id="menuNavigation">
<action bean="navigationController" method="calculateMenuNavigation"/>
<transition on="stepA" to="stepA" />
<transition on="stepB" to="stepB" />
<transition on="stepC" to="stepC" />
</action>


and then each <view-state> has a catch all "*" entry which will send any _eventId which it receives which is not in the flow back to the menuNavigation <action-state>.



<view-state id="stepA" view="aPage">
<transition on="continue" to="stepB" />
<transition on="*" to="menuNavigation" />
</view-state>


Since every <action-state> needs an <action>, I setup a bean which returns the source event.



public class NavigationController extends MultiAction &#123;
public Event calculateMenuNavigation&#40;RequestContext context&#41; throws Exception &#123;
return context.getSourceEvent&#40;&#41;;
&#125;
&#125;



It is then as simple as setting up a menu with hyperlinks.


<a href="<c&#58;url value="/flow.htm?_flowExecutionId=$&#123;flowExecutionId&#125;&_eventId=stepA"/>">Step A</a>
<a href="<c&#58;url value="/flow.htm?_flowExecutionId=$&#123;flowExecutionId&#125;&_eventId=stepB"/>">Step B</a>
<a href="<c&#58;url value="/flow.htm?_flowExecutionId=$&#123;flowExecutionId&#125;&_eventId=stepC"/>">Step C</a>

kajism
Aug 5th, 2005, 08:24 AM
Really cool! Thanks!!

Your approach allows to correctly terminate all running subflows using <transition on="*" to="end"/> in each state and by forwarding the "unknown" (known to menu flow) event using this slightly modified EndState:



endState = new EndState&#40;getFlow&#40;&#41;, "end"&#41; &#123;
protected org.springframework.webflow.Event subflowResult&#40;org.springframework.webflow.RequestC ontext context&#41; &#123;
return new Event&#40;this, context.getSourceEvent&#40;&#41;.getId&#40;&#41;&#41;;
&#125;;
&#125;;


the root (menu) flow can launch the new requested flow.

This enables us to have a menu on any page and achieve strong combination of controlled and free browsing.

SWF is really cool! Thanks guys!
Karel