检测Validator

时间:2017-05-23 06:30:31

标签: spring-webflow transitions spring-webflow-2 spring-validator event-id

我使用Spring Webflow 2,我需要在验证器中检测已触发的转换事件ID。

在我的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>

我的顾问&#34;顾问&#34;模特

@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?

}

我希望我在代码段中的评论中非常清楚。 任何帮助将不胜感激。

另外

RequestContextHolder.getRequestContext().getCurrentEvent()

无效,因为它返回null

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

它实际上包含事件ID,但它的getter受到保护,所以我无法获得它。

1 个答案:

答案 0 :(得分:0)

这不是最佳解决方案,但至少可以解决问题。 这就是我获取转换ID和视图状态ID的方式。

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