【问题标题】:Detect Spring Web Flow transition event id in Validator在验证器中检测 Spring Web Flow 转换事件 id
【发布时间】:2017-05-23 06:30:31
【问题描述】:

我使用 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>

我的“顾问”模型验证器

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

}

我希望我对代码 sn-p 中的 cmets 非常清楚。 任何帮助将不胜感激。

还有

RequestContextHolder.getRequestContext().getCurrentEvent()

没有帮助,因为它返回 null

至于

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

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

【问题讨论】:

  • 我觉得这听起来很熟悉。我在stackoverflow.com/questions/14544931/… 的回答表明getCurrentEvent().getId() 应该做你想做的事。我很确定我当时测试过它。听起来像问那里的人也得到了getCurrentEvent() 的非空值。所以我想知道你为什么会变成空值。哪个版本的 WebFlow?
  • 他在 getCurrentEvent() 上也得到了空值,他最终得到的解决方案不符合我的需要。无论如何,谢谢。
  • 另外,我使用 Spring Web FLow 2.4.4
  • 他没有得到空值,他说,“是的 getCurrentEvent().getAttributes() 返回所有请求属性的映射”。
  • 哦,好吧,对不起,这是他有“好主意 dbreaux。不幸的是,我试过了,getCurrentTransition() 在我的验证器中返回 null”。但是我仍然在 getCurrentEvent() 上得到 null 并且 getCurrentView().getUserEventState() 有 id 但它受到保护,我无法获得它。

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-08-29
    • 2014-04-28
    • 2012-08-24
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多