Jason
Jason

Reputation: 4130

Webflow On-Render/On-Entry Exception Still Runs On-Exit Methods

I have the following defined in my flow definition:

<view-state id="switchboard" view="switchboard2" model="reservationForm">
    <on-entry>
        <evaluate expression="flowController.enterSwitchboard(flowRequestContext)" />
        <evaluate expression="flowController.populateActionFlags(flowRequestContext)" />
    </on-entry>
    <transition on="prev" to="switchboardAction" validate="false" />
    <transition on="*" to="switchboardAction" />
    <transition on-exception="java.lang.Exception" to="systemErrorView" />
    <on-exit>
        <evaluate expression="flowController.exitSwitchboard(flowRequestContext)" />
        <evaluate expression="flowController.clearWebflowForms(flowRequestContext)" />
    </on-exit>
</view-state>

What is happening is that an error (in this particular case, IllegalArgumentException, but could be other exceptions as well) in the populateActionFlags() method is ocurring, but the exitSwitchboard() method is still firing. After this, the clearWebflowForms() method throws an exception because the model is screwed up as a result of the previous exception. This is causing an infinite loop.

What I need is this: when an exception occurs, bypass the on-exit methods and go to an error state ("systemErrorView") defined in a section. Do not pass go, do not collect $200.

Webflow version is 2.4.1.

Can anyone assist?

Jason

Upvotes: 1

Views: 1341

Answers (2)

JanPl
JanPl

Reputation: 804

on-exit is to be executed at the end of a view state with intent. Declaring it means the same as a finally block in java.

In your case you may want to do this

<transition on="prev" to="switchboardAction" validate="false" >
    <evaluate expression="flowController.exitSwitchboard(flowRequestContext)" />
    <evaluate expression="flowController.clearWebflowForms(flowRequestContext)
</transition>
<transition on="*" to="switchboardAction" >
    <evaluate expression="flowController.exitSwitchboard(flowRequestContext)" />
    <evaluate expression="flowController.clearWebflowForms(flowRequestContext)
</transition>

This executes the evaluate statements on each transition but not on exception.

Upvotes: 1

rptmat57
rptmat57

Reputation: 3787

try using a global transition in your flow:

<global-transitions>
    <transition on-exception="java.lang.Exception" to="systemErrorView"/>
</global-transitions>

keep in mind this will be shared by all states of your flow.

If you don't want it to be shared, you might want to create a custom exception for this.

Upvotes: 1

Related Questions