I am using Spring Web Flow 2.3 and I have a page that has two forms on it that transition to different places depending on which is submitted. To accomplish this, I have one composite model object for my view-state that holds the two forms inside. The problem I am seeing is that if transition A is fired, I only want to validate form A, and likewise with form B - only want to validate B if B transition fired. I am not sure how to indicate which form to validate. View state that is validating the entire compositeForm for each transition:
<view-state model="compositeForm">
<transition on="formAsubmit" to="formApage" validate="true"/>
<transition on="formBsubmit" to="formBpage" validate="true"/>
</view-state>
Does anyone know how I can trigger a custom validator to validate differently depending on which transition was fired?
Thanks for you help.
Steve
What I ended up doing was to manually trigger my validation when form B was submitted and transition to a decision-state that checks if there were validation errors. It's a little ugly, but I feel like it's the best way:
This is not the best solution, but at least is solves the problem. This is how I obtained my transition id and view-state id in vlaidator.
Transition id
view-state id
I don't know about a custom validator for each, but within your validation method, I think you could use the
RequestContextHolder.getRequestContext()
togetCurrentTransition()
orgetCurrentEvent()
and compare manually to thegetId()
value.