【问题标题】:How to call flow from @controller?如何从@controller 调用流?
【发布时间】:2013-10-05 20:40:48
【问题描述】:

当我导航 /app/wb/create 时,我将进入下面的控制器方法,该方法需要调用流程 "/app/main" 但弹簧将其恢复为 "/main.xhtml" 。我的问题是如何从 spring 控制器重定向到流?

@Controller
@RequestMapping("/wb")
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */

        @RequestMapping("/create/")
        public String home(Device device, Model model) {
            if (device == null) {
                logger.info("no device detected");
            } else if (device.isNormal()) {
                logger.info("Device is normal");
            } else if (device.isMobile()) {
                logger.info("Device is mobile");
            } else if (device.isTablet()) {
                logger.info("Device is tablet");
            }
            return "app/main"; // Where main is the flow id
        }
}

流程

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow
        http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

    <var name="user" class="com.veera.myapp.domain.UserEntity" />
    <view-state id="welcome" view="welcome.xhtml">
        <transition on="newUser" to="signUp" />
    </view-state>

    <view-state id="signUp" view="signUp.xhtml" model="user">
        <transition on="backToSignIn" to="welcome" />
    </view-state>
</flow>

【问题讨论】:

    标签: spring-mvc spring-webflow


    【解决方案1】:
    return "/main";
    

    您必须删除您的应用程序路径

    【讨论】:

    • 那会从流中找到视图吗?
    • 当我添加“/main”时,它正在寻找 /main.xhtml 而不是来自 webflow 的视图主视图。
    • 流程默认从flow.xml中定义的第一个状态开始
    【解决方案2】:
    return "redirect:/main.xhtml"
    

    你必须告诉控制器重定向。

    【讨论】:

    • 需要重定向到flow而不是xhtml页面。
    • 你的 webflow 配置是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2021-11-24
    • 1970-01-01
    • 2021-05-29
    • 2018-02-19
    • 2012-07-23
    相关资源
    最近更新 更多