【问题标题】:Spring Web Flow: append view state id to URLSpring Web Flow:将视图状态ID附加到URL
【发布时间】:2014-03-20 06:44:26
【问题描述】:

我正在使用 spring web flow 2.x 并尝试将视图状态 ID 附加到 URL。我想保存视图状态 ID 以请求范围并将其附加到 URL 每次用户单击“下一个”或“上一个”时。这是否可以使用自定义流 URL 处理程序?

如何在我的 Custom/Pretty flow Url 处理程序中获取视图状态 ID?

【问题讨论】:

    标签: java spring spring-mvc spring-webflow-2


    【解决方案1】:

    在视图中编写一个入口操作并通过 RequestContext 检索当前状态 id。

    <view-state id="currentView" view="currentView" model="modelObject">
        <on-entry>
            <evaluate expression="yourObject.methodName(flowRequestContext, flowScope.modelObject)"/>
        </on-entry>
        <transition on="previous" to="someStateOrView"/>
        <transition on="next" to="someStateOrView"/>
     </view-state>      
    
     public class YourObject{
    ...
    public void methodName(RequestContext requestContext, ModelObject model){
        model.setPreviousView(requestContext.getCurentState().getId());
        ....
    }
     }
    

    从您的模型中获取 previousView 值并将其附加到您的 url,因为这将在流程进入此视图时设置。

    【讨论】:

    • 但是如何在我的自定义流 URL 处理程序中获取附加到 URL 的视图状态。我正在使用此处的示例。[forum.spring.io/forum/spring-projects/web/web-flow/…
    • 换句话说,如何在我的 Flow Url 处理程序中获取请求上下文?
    • RequestContext requestContext = RequestContextHolder.getRequestContext(); String viewName = requestContext.getCurrentState().getId();
    猜你喜欢
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 2011-01-05
    • 1970-01-01
    相关资源
    最近更新 更多