0

I have a flow that has an input required="true". If for some reason a person bookmarks or shares a link to the middle of the flow, since there's no input, the flow throws an exception for the missing input, and I get a generic 500 error page. Is there a way to specify a view to be rendered in this case?

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • possible duplicate of [Spring Web Flow exception handling](http://stackoverflow.com/questions/13086376/spring-web-flow-exception-handling) – Tony Apr 16 '15 at 09:59
  • @Tony That question is dealing with exceptions on views or transitions, not on the entry to the flow itself, which doesn't appear to have an explicit hook. – chrylis -cautiouslyoptimistic- Apr 16 '15 at 10:26
  • @chrylis Tony is correct in the sense that if you use required="true" all that will do is throw an exception (that you must catch and handle appropriately) indicating that the param was missing.. Although the syntax is concise I personally do not use required="true" for the reason just stated and manually validate the input params myself. See my answer below – Selwyn Apr 17 '15 at 15:30
  • @Airduster It's not *possible* to catch that exception. It's thrown from code that's higher-level than the flow itself. – chrylis -cautiouslyoptimistic- Apr 17 '15 at 15:45
  • @chrylis Maybe that's why I opted to use the manual solution for this problem all this time :) I've never tried this but maybe you can handle the exception if you pass the input param from a parent flow -> subflow? and maybe the parent flow can handle the exception throw from the subflow using the link/answer tony supplied. I suspect the "required" attribute in the input tag was only meant to be used with subflows (much like the output tag only works in subflows passing back values to/from parent caller flow) – Selwyn Apr 17 '15 at 18:14

1 Answers1

1

Remove the input required="true" attribute and validate the input param yourself via a decision-state.

For example:

<input name="id"/>

<decision-state id="createOrEdit">
      <if test="requestParameters.id != null" then="editView" else="createView"/>
</decision-state>

<view-state id="createView" view="flows/v/create" model="modelObj"> 
           <!-- contents omitted -->
</view-state>

<view-state id="editView" view="flows/v/edit" model="modelObj"> 
           <!-- contents omitted -->
</view-state>

So in the above example we receive a request parameter of 'id'. We validate this parameter to see if it is null or not and make a decision as to which view-state to proceed to based on this null check.

Optionally,

  1. Inside the 'if' the values of "then" and "else" can reference not just view-states but any other action-state or even another decision-state.

  2. you can add multiple 'if tests' within 1 decision-state.

Selwyn
  • 3,118
  • 1
  • 26
  • 33