如何在进入JSP页面之前设置Form Bean

发布于 2024-12-12 09:38:45 字数 2274 浏览 2 评论 0原文

我是一个绝对的初学者。因此,如果我错过了显而易见的内容,请耐心等待。

我使用的环境: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>

Form Bean:

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

I am an absolute beginner. So please bear with me if I miss the obvious.

Environment I am using: Spring Portlet MVC (3.0), Liferay 6.0.6

I have a controller, a form bean and a JSP page.
I am able to successfully submit a form and get the form bean by using the below code. However I am stuck on how to preload some values into my form bean before the bean is forwarded to JSP. Can somebody point out the right direction:

My Controller:

@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();
}

My JSP Page:

<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>

Form Bean:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-12-19 09:38:45

在渲染方法 resetPasswordView 中,将一个名为 resetPasswordCriteria(jsp 中的 commandName)、类型为 ResetPassword 的对象放置到模型中。

In your rendering method resetPasswordView, place an object named resetPasswordCriteria (your commandName in jsp) of type ResetPassword to the model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文