@ActionMapping无法重定向到View

时间:2016-06-16 13:10:30

标签: spring forms liferay

在Liferay论坛上发帖here

我有一个Spring表单,用于更新提交时的用户信息。表单应该在保存后将用户重定向回表单,以及有关其输入表单的任何成功/错误消息。我的问题是我无法让@ActionMapping重定向回form视图。我按照指南here,但没有运气。

@ActionMapping(params ={"action=saveUser"})
public void saveUser(
    @ModelAttribute("user") User user,
    BindingResult result,
    ActionRequest actionRequest,
    ActionResponse actionResponse) throws IOException {     
    ModelAndView mav = new ModelAndView("form");
    try {
        userRepo.save(user);
        mav.addObject("success", "User successfully saved");
        actionResponse.setRenderParameter("action", "success");
    } catch (Exception e){
        actionResponse.setRenderParameter("action", "failure");
    }
}


@RenderMapping(params = "action=success")
public ModelAndView viewSuccess() {
    ModelAndView mav = new ModelAndView("form");
    mav.addObject("success", "stuff");
    return mav;
}

@RenderMapping(params = "action=failure")
public String viewFailure() {
    ModelAndView mav = new ModelAndView("form");
    mav.addObject("failure", "other stuff");
    return mav;
}

用户成功保存后,应调用viewSuccess()方法并返回表单,但永远不会调用它。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

如果你已经按照上面提到的教程而不是缺少以下一行

<action-url-redirect>true</action-url-redirect>
在您的portlet <{p>>下的liferay-portlet.xml