【问题标题】:How to Set Form Bean before it goes to JSP page如何在表单 Bean 进入 JSP 页面之前设置它
【发布时间】:2011-10-27 18:52:16
【问题描述】:

我是一个绝对的初学者。所以,如果我错过了显而易见的事情,请多多包涵。

我使用的环境:Spring Portlet MVC (3.0)、Liferay 6.0.6

我有一个控制器、一个表单 bean 和一个 JSP 页面。 我可以使用以下代码成功提交表单并获取表单 bean。但是,在将 bean 转发到 JSP 之前,我被困在如何将一些值预加载到我的表单 bean 中。有人能指出正确的方向吗:

我的控制器:

@ActionMapping(params = "spring_action=resetPasswordViewAction")
protected void resetPasswordAction(ActionRequest actionRequest, Map<String, Object> model, ActionResponse actionResponse, @RequestParam String customerId, @RequestParam String userName) {
    model.put("customerId", customerId);//Preload form bean value with this
    model.put("userName", userName);//Preload form bean value with this
    actionResponse.setRenderParameter("spring_render", "resetPasswordView");
}

@RenderMapping(params = "spring_render=resetPasswordView")
protected ModelAndView resetPasswordView(RenderRequest renderRequest, Map<String, Object> model) {
    return new ModelAndView("resetPassword", model);
}

@ActionMapping(params = "spring_action=resetPasswordUpdateAction")
protected void resetPasswordUpdateAction(ActionRequest actionRequest, Map<String, Object> model, ActionResponse actionResponse, final ResetPassword resetPasswordCriteria) {
    LOG.info(resetPasswordCriteria.toString());// Form values are retrieved successfully
    actionResponse.setRenderParameter("spring_render", "resetPasswordView");
}

@ModelAttribute("resetPasswordCriteria")
public ResetPassword getResetPasswordCriteria() {
    return new ResetPassword();
}

我的 JSP 页面:

<form:form id="resetPasswordForm" name="resetPasswordForm" commandName="resetPasswordCriteria" method="post" action="${resetPasswordUpdateActionURL}">

    <form:label path="customerId" /><!--Preload this field value-->
    <form:label path="userName" /><!--Preload this field value-->
    <form:password path="password" />
    <form:password path="confirmPassword" />
    <input type="submit" value="Submit" />

</form:form>

表单 Bean:

public class ResetPassword {
    private String customerId = "";
    private String userName = "";
    private String password = "";
    private String confirmPassword = "";
    //Getters Setters
}

【问题讨论】:

    标签: spring spring-mvc liferay portlet liferay-6


    【解决方案1】:

    在您的渲染方法 resetPasswordView 中,将类型为 ResetPassword 的名为 resetPasswordCriteria(jsp 中的命令名称)的对象放置到模型中。 p>

    【讨论】:

    • 是的,我更改了动作和渲染的签名以匹配它... @RenderMapping(params = "spring_render=resetPasswordViewRender") protected ModelAndView resetPasswordViewRender(@ModelAttribute("resetPasswordCriteria") final ResetPassword resetPasswordCriteria,RenderRequest renderRequest, Map model)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2012-01-02
    • 2010-11-08
    相关资源
    最近更新 更多