Accessing flash attributes in Spring Web flow

混江龙づ霸主 提交于 2019-12-22 01:55:10

问题


I use,

   redirectAttributes.addFlashAttribute("msg","Level complete")

to access message on the redirected jsp.

How can I use this redirect attribute when I am redirecting to a Webflow ?


回答1:


When flash attribute is used to send data from one controller to a webflow we have to bind redirected flash attribute (from controller) to the response JSP page of the webflow. For this purpose we can maintain a backend FormAction class to bind the value to any scope of webflow. In flow xml we can can call custom method on entry of a view state.

Custom Method of FormAction class would be like

public void setupReferenceData(RequestContext context) throws Exception {
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getNativeRequest();
        Map<String, ?> inputFlashMap = RequestContextUtils.getInputFlashMap(request);
        if (inputFlashMap != null) {
            String flash = (String) inputFlashMap.get("flash");
            context.getRequestScope().put("flash1", flash);
        }
    }

This method call should be included in the entry section of a view state. So flow xml should have these portion.

<view-state id="request" view="hello">
            <on-entry>
                <evaluate expression="requestAction.setupReferenceData" />
            </on-entry>
            <transition on="next" to="helloend"/>
    </view-state>


来源:https://stackoverflow.com/questions/23216312/accessing-flash-attributes-in-spring-web-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!