Webflow stepping back and forth between view states - spring

I'm learning to use Spring Webflow. I want to create a from which is working like an old school installer. At every view-state i have a next and a back button.
My question would be that is it possible to programmatically determine which is the next view-state or the one before the current one? So I can provide that information to my buttons?

Yes you can do this but you would have to EXPLICITLY predefine each transition/jump within that specific viewstate inside the flow xml file.
For example:
(assume we have the following view-states defined in our webflow file)
<view-state id="viewStateA">
<transition on="gotoB" to="viewStateB"/>
<transition on="gotoC" to="viewStateC"/>
</view-state>
<view-state id="viewStateB">
<transition on="gotoA" to="viewStateA"/>
<transition on="gotoC" to="viewStateC"/>
</view-state>
<view-state id="viewStateC">
<transition on="gotoA" to="viewStateA"/>
<transition on="gotoB" to="viewStateB"/>
</view-state>
So if you're currently in viewStateC. You can ONLY transition/goto either viewStateA or viewStateB because you predefined them as possible transitions inside (from) viewStateC.
...
And to trigger any transition all you have to do is make a HTTP-GET request that looks like this passing the 'on' value for the specific transition desired as the '_eventId' like this:
${flowExecutionUrl}?_eventId=gotoA
In this case the the transition 'gotoA' will be triggered which in turn will take us back to 'viewStateA'
So to answer your question... aslong as you know the transition 'on' name and it is predefined within that view-state you can programmatically trigger/goto which ever view-state/action-state/decision-state you desire by making the HTTP-GET request to the desired transition.

Related

Resuming spring webflow from action state

Is there an option in spring webflow to resume flow from action-state or decision-state?
The flow that I need to implement requires jumping off the flow to click some link in the email. I have the controller that handles the email link and I'm trying to resume previous flow, but not from the last view state.
I have something like this
<view-state id="start>
<transition on="submit" to="handleStep1"/>
</view-state>
<action-state id="handleStep1"/>
<evaluate expression="a.something()"/>
<transition on="emailSent" to="show-email-sent"/>
<transition on="changeSomething" to="show-change"/>
</action-state>
<view-state id="show-email-sent" view="emailSentPage">
</view-state>
<view-state id="show-change" view="showChangePage">
</view-state>
When action state decides to send out the email, user is show the email sent page. Now he will click the link in the email, and he should get back to the action state which will decide that now he can go to "show-change" page.
I am able to resume flow by getting the flowRequestContext.getFlowExecutionUrl() and then using it in the controller that handles the email click, but this url always redirects to the view-state (depending on when I save its value it points to the starting view-state or the email-sent view state. How can I resume the flow from the action-state? Or maybe other idea how to handle such case?
You could add a parameter in the link in your email, i.e. http://yoursite.com/yourflow?resume=true
then, add an non required input in your flow:
<input name="resume" required="false" type="boolean"/>
add a decision-state to deal with it:
<decision-state id="resumeOrNotResume">
<if test="resume == null || !resume" then="start" else="showChange"/>
</decision-state>
and set it as a start state:
<flow start-state="resumeOrNotResume">

spring web flow: passing parameter from second flow to previous

I have 2 flows. I want to go back to first flow from second when the user clicks on cancel, and I want to show the old content of flow 1. I'm trying to pass a value like this:
<view-state id="backHome" view="externalRedirect:contextRelative:/home.do?homeId=oldHomeId" />
And from first flow. I'm trying to set the value to the view:
<input name="backHome" />
<on-start>
<set name="requestScope.backHome" value="backHome" />
</on-start>
The value is not showing in jsp when I tried with: ${backHome}
What is the proper way to load previous flow content when do a cancel from second flow? Any advice will be appreciated. :)

Navigating from one page to Another page in spring webflow

can anyone give a simple example for spring webflow to navigate from one page to another page using a button
you need to be more a little more specific. but if you just want to navigate from one page to another, in terms of Webflow you can do this in the same flow:
these 2 pages will be 2 view-state and by clicking on a button you want to trigger an event that will transition you to from one to the other.
<view-state id="viewState1" view="viewPage1.html">
<transition on="nextPage" to="viewState2"/>
</view-state>
<view-state id="viewState2" view="viewPage2.html">
<transition on="previousPage" to="viewState1"/>
</view-state>
in your web page, you just need a submit button like this:
page 1:
<input type="submit" name="_eventId_nextPage" value="Next Page"/>
page 2:
<input type="submit" name="_eventId_previousPage" value="Previous Page"/>
I strongly advice you to read the documentation and some tutorials as there are many ways to accomplish this

Invoke a particular view-state in a flow in Spring Web FLow

In our Spring App, under some test scenarios we need to invoke a particular view-state in a flow which may or may not be the start-state in the flow. Is there any way in which this can be done?
Usually whenever we hit a url, it invokes the start-state of that flow, however here we need to invoke a specific view-state.
Thanks.
We wanted to do something similar, although much more limited, so that we could provide direct links into the second view-state of the flow as if the user had visited the first view-state and filled its input form with specific data.
You might be able to use this kind of approach to accomplish what you're asking, but then, of course, regular users could do the same thing as well.
So just for reference, here's what we did, making the starting state be an action-state that looks for input parameters and deciding from those where to transition to.
<var name="queryForm" class="package.QueryForm"/>
<!-- Allow input parameters for direct links -->
<input name="number"/>
<input name="name"/>
<action-state id="begin">
<evaluate expression="number != null and name != null"/>
<transition on="yes" to="findAccount">
<set name="queryForm.number" value="number"/>
<set name="queryForm.name" value="name"/>
</transition>
<transition on="no" to="formInput"/>
</action-state>
<view-state id="formInput" view="formInput" model="queryForm">
<transition on="submit" to="findAccount"/>
</view-state>
<action-state id="findAccount">
<evaluate expression="actionInstance.findAccount"/>
....
</action-state>

Spring Webflow | Different validate method per transition

I currently have a Spring Webflow application that uses Webflow + Ajax.
I have a view-state called "A" that has several transitions.
<view-state id="A" model="myClass">
<transition on="X1" .../>
<transition on="X2" .../>
<transition on="X3" .../>
</view-state>
The problem is that each transition should validate only a portion of "myClass" and not all. By default Spring Webflow has a single method to validate.
Basically what I need is to call a different validate method on each transition instead of having a single one.
Is this possible? Any ideas on how to do this?
Thanks in advance!!!
Why not use one ValidationClass for view state?
You can get the event that triggert the validation by calling
public String getUserEvent();
on the ValidationContext.
Then, depending on the result do whatever you want to validate.
It is possible to use an attribute called validatorMethod to specify a particular method to call on the validator as described here. Here is a modified example from the Javadoc showing how do do this:
<view-state id="displayCriteria">
<on-render>
<evaluate expression="formAction.setupForm"/>
</on-render>
<transition on="search" to="executeSearch">
<evaluate expression="formAction.bindAndValidate">
<attribute name="validatorMethod" value="validateSearchCriteria"/>
</evaluate>
</transition>
</view-state>
This is assuming that the validator defined for searchFormAction has a method called validateSearchCriteria.

Resources