Display Spring WebFlow Global Transitions - spring

I am a new at using Spring Webflow. I am trying to use Global transitions. In my jsp I am trying to display all the transitions using
<c:forEach var="transition" items="${flowRequestContext.currentState.transitions}">
<c:out value="${transition.id}"/>
</c:forEach>
I can see all the transitions for the currentState but I cannot see the global transitions.
My understanding was the global transitions would be available in all the view-states. To get the global transitions do I need to access it in a different way?
Here is a simplified version of my flow xml
<flow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/webflow"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<view-state id="state1" view="view1.jsp" model="person">
<transition on="submit" to="state2"/>
<transition on="cancel" to="canceled"/>
</view-state>
<view-state id="state2" view="view1.jsp" model="person">
<transition on="complete" to="complete"/>
</view-state>
<view-state id="canceled" view="view1.jsp" model="person">
<transition on="resubmit" to="resubmit"/>
</view-state>
<action-state id="reassign">
<evaluate expression="CustomAction.reassign(flowRequestContext)"/>
</action-state>
<end-state id="complete"/>
<global-transitions>
<transition on="cancel" to="canceled"/>
<transition on="reassign" to="reassign"/>
</global-transitions>
</flow>
So when in state1 in the jsp how canI display all the tranistions including global?
Thanks for any help in advance

Better late than never.
There is a getGlobalTransitionSet method, but it's in the implementation org.springframework.webflow.engine.Flow class, not in the interface FlowDefinition. This method returns a TransitionSet that is not iterable by forEach, but fortunatelly it has a toArray method.
If you feel comfortable with this, you could use:
${flowRequestContext.activeFlow.globalTransitionSet.toArray()}
Tested.

Related

Invalid _eventId in spring webflow

Is there any way to handle unexisting eventIds or absence of eventId parameter in spring webflow?
e.g. for this webflow
<flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<view-state id="welcome">
<transition on="goForward" to="nextStep"/>
</view-state>
<view-state id="nextStep">
<transition on="endFlow" to="finishStep" />
</view-state>
<end-state id="finishStep"/>
<global-transitions>
<transition on="cancel" to="finishStep"/>
</global-transitions>
</flow>
How to handle requests with param like _eventId=unexistingAction or requests with no _eventId param ?
This will normally produce a page with stack trace...
no transition found on occurence of event in state of flow...
This is how you can handle transitions that don't exist:
<global-transitions>
<transition on-exception="org.springframework.webflow.engine.NoMatchingTransitionException" to="handlingViewState">
<evaluate expression="handlingBean.handle(flowExecutionException)"></evaluate>
</transition>
</global-transitions>

transition is not invoked on view-state in spring webflow

Transition is not invoked in my view-state and when I click the fogotusername link in my login page, it again lands to the login page itself. I think the webflow session is somehow lost. Any idea? Please help.
fogotUsername link in my login.jsp is below:
<a href="login.do?_eventId=fogotUsername&page=init" > <spring:message code="label.forgetUsername" /></a>
My login flow xml is below:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd" start-state="login">
<view-state id="login" view="tiles.login">
<transition on="fogotUsername" to="viewForgotUsername">
</transition>
<transition on="fogotPassword" to="viewForgotPassword">
</transition>
</view-state>
<view-state id="viewForgotUsername" view="tiles.forgotUsername">
</view-state>
<view-state id="viewForgotPassword" model="password" view="tiles.changePassword">
<transition on="submit" to="viewForgotUsername"/>
</view-state>
<end-state id="loginend"/>
</flow>
The link doesn't contain the flow execution URL. Try replacing your link element with the below:
<spring:message code="label.forgetUsername" />

Spring Web Flow exception handling

How to prevent exception,
if requestParameters.sortBy is passed as string (java.lang.NumberFormatException) or is missing (java.lang.NullPointerException)?
<view-state id="journeySearch" model="journeyForm">
...
<transition on="sort">
<set name="journeyCriteria.sortBy" value="requestParameters.sortBy" type="int" />
<evaluate expression="bookingService.searchJourneys(journeyCriteria)" result="viewScope.journeys" />
</transition>
</view-state>
requestParameters.sortBy will be null if it doesn't exist, but it should not throw a NullPointerException
about the NumberFormatException, you could use something like that:
<global-transitions>
<transition on-exception="java.lang.NumberFormatException" to=""/>
</global-transitions>
you could also implement your own exception-handler and use it with <exception-handler bean=""/> you can use it at the flow or state level.

Restarting Spring Web Flow with new model values

I am trying to find a way that if the user restarts the flow the values are not in it. If you look at my flow below you can see that the user enters data, previews it and then saves it.. after the save the user can go back to enter new data into the input screen but with my current setup the screen shows the pre-data. how can I clear it on restart?
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var name="customer" class="org.uftwf.domain.Customer"/>
<view-state id="helloworld" view="input.jsp" model="customer" popup="true">
<transition on="submit" to="preview" />
<transition on="cancel" to="thanks" validate="false"/>
</view-state>
<view-state id="preview" model="customer">
<transition on="cancel" to="helloworld"/>
<transition on="accept" to="save">
<evaluate expression="hellowWorldFlowActions.addCustomer(customer)"/>
</transition>
</view-state>
<view-state id="save" model="customer">
<transition on="accept" to="thanks"/>
</view-state>
<view-state id="thanks">
<transition on="restart" to="helloworld"/>
</view-state>
</flow>
One simple way is to define a reset() method on your Customer class and call that in whichever <view-state> <on-entry> (like "thanks") or <transition> ("restart") makes sense.
Have you tried:
<view-state id="helloworld" view="input.jsp" model="customer" popup="true">
<on-entry>
<set name="flowScope.costumer" value="new org.uftwf.domain.Customer()" />
</on-entry>
<transition on="submit" to="preview" />
<transition on="cancel" to="thanks" validate="false"/>
</view-state>
You can do an external redirect to do same flow. Here is an example.
<var name="customer" class="org.uftwf.domain.Customer"/>
<view-state id="thanks">
<transition on="restart" to="doRestart"/>
</view-state>
<end-state id="doRestart" view="externalRedirect:nameOfThisFlow"></end-state>

String var assigned to view-state?

I am not sure if this is possible in webflow 2.2.1
flow.xml
<view-state id="flowId1" model="flowModel1" view="/WEB-INF/templates/Flow_Form/form1.jsp">
<set attribute="strVar" value="${'someStringVar'}" />
<transition on="step1" to="step1Action" />
</view-state>
jsp
<h1>${strVar}</h1>
Essentially, I'd like to assign a String var that will change value accross individual view-states, that is set in the flow.xml..
Are there any other simple recommended approaches to this?
Thanks
got it.. :)
<view-state id="flowId1" model="flowModel1" view="/WEB-INF/templates/Flow_Form/form1.jsp">
<on-entry>
<evaluate expression="'someStringVar'" result="flowScope.strVar"/>
</on-entry>
<transition on="step1" to="step1Action" />
</view-state>

Resources