Detect Spring Web Flow transition event id in Validator

943 views Asked by At

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.

1

There are 1 answers

0
Marta Ginosian On BEST ANSWER

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();