spring web flow: passing parameter from second flow to previous - spring

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. :)

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">

Triggering event on input/select value change with Spring web flow

I wanna trigger flow change when user change the value in select box:
<select>
<options>
<option>1</option>
<option>2</option>
</options>
</select>
After reading this docs: https://docs.spring.io/spring-webflow/docs/current/reference/html/spring-mvc.html#spring-mvc-resuming-on-event
I did not find the answer.
Please can any one help? Any advice appreciated.
The change I wanna achieve is to set button to be activated, when value has been chosen from select box.
there are 2 ways to do this:
First, using strictly javascript (all in the UI), by using onchange and/or onclick on your select element to find the button and activate/deactivate it
Second, using Webflow:
submit the form on onchange
re-render the view with the proper changes
Assuming you want to go with webflow here, you can use this:
JSP
<form id="myFormId" action="${flowExecutionUrl}" method="post">
<select id="mySelectId" onchange="Spring.remoting.submitForm('mySelectId', 'myFormId', {fragments:'body', _eventId: 'myChangeEvent'}); return false;">
...
</select>
</form>
Flow
<view-state id="myViewStateId">
<transition on="myChangeEvent" validate="false" bind="true">
<!-- change some property to enable your button -->
</transition>
</view-state>
This will re-render the view and the property/attribute you are using to enable/disable your button will be updated.
It is important to use validate="false" otherwise validation error(s) could prevent your transition from succeeding

Webflow stepping back and forth between view states

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.

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>

Resources