1

I use Spring Webflow 2 and I need to detect the fired transition event id in my validator.

In my flow.xml

<view-state id="stepFinal" view="/registration/consultant/registr-step-final" model="consultant">

    <transition on="addSkill" to="stepFinal" validate="true" bind="true"/>
    <transition on="deleteSkill" to="stepFinal" validate="true" bind="true"/>
    <transition on="back"  to="stepOne"  validate="true" bind="true"/>
    <transition on="preview" to="stepPreview" validate="true" bind="true"/>

</view-state>

My validator for "consultant" model

@Component
public class ConsultantValidator implements Validator {

public boolean supports(Class clazz) { return clazz.equals(ConsultantRegistrationModel.class); }

public void validate(Object object, Errors errors) {
    ConsultantRegistrationModel consultantModel = (ConsultantRegistrationModel) object;

    // My validations here
    // Here I want to detect the event id which was fired.
    // For example (see in my flow.xm) 
    // I have: 
    // transition on="addSkill"
    // transition on="deleteSkill"
    // transition on="back"
    // transition on="preview"


    // I want to detect here if is it "addSkill" or "deleteSkill" or "back" or "preview"?
    // Any solutions?

}

I hope I'm super clear in my comments in the code snippet. Any help would be much appreciated.

Also

RequestContextHolder.getRequestContext().getCurrentEvent()

doesn't help as it returns null

and as for

RequestContextHolder.getRequestContext().getCurrentView().getUserEventState()

It actually contains event id but its getter is protected so I can't obtain it.

Marta Ginosian
  • 117
  • 1
  • 8
  • I thought this sounded familiar. My answer at https://stackoverflow.com/questions/14544931/spring-web-flow-multiple-forms-on-page-validating-correct-form/ indicates that `getCurrentEvent().getId()` should do what you want. I'm pretty sure I tested it back then. Sounds like the person asking there got non-null for `getCurrentEvent()` too. So I wonder why you're getting null. Which version of WebFlow? – dbreaux May 23 '17 at 16:08
  • He got null on getCurrentEvent() as well and the solution he ended up with doesn't fit my needs. Anyway, thank you. – Marta Ginosian May 24 '17 at 10:33
  • Also, I use Spring Web FLow 2.4.4 – Marta Ginosian May 24 '17 at 10:38
  • He didn't get a null, he said, "yes getCurrentEvent().getAttributes() returns a map of all of the request attributes". – dbreaux May 24 '17 at 13:00
  • Oh ok, sorry this is where he had "Good idea dbreaux. Unfortunately, I tried it, and getCurrentTransition() is returning null in my validator". But still I get null on getCurrentEvent() and getCurrentView().getUserEventState() has the id but its protected and I can not obtain it. – Marta Ginosian May 25 '17 at 08:12
  • Right, so... I'm wondering what's different between us then, and you now. If I get a chance, I'll try a simple case with latest version. If it used to work and no longer does, might be worth creating a bug at JIRA. https://jira.spring.io/ – dbreaux May 25 '17 at 13:17

1 Answers1

0

This is not the best solution, but at least is sloves the problem. This is how I obtained my transition id and view-state id.

 RequestContextHolder.getRequestContext().getCurrentView().getUserEventState().toString().split("eventId = ")[1].split("mappingResults")[0].replaceAll("[^a-zA-Z]", "");
 RequestContextHolder.getRequestContext().getFlowExecutionContext().getActiveSession().getState().getId();
Marta Ginosian
  • 117
  • 1
  • 8