Announcement Announcement Module
Collapse
No announcement yet.
Field return empty after form validation error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Field return empty after form validation error

    I'm trying to do a password/confirmationPassword register form. I dont want confirmationPassword in my Model. When I save my form with errors, the confirmationPassword field comes back empty

    Code:
    <form:form modelAttribute="user" action="save" method="POST">
    	<form:input id="user-form-username" path="username" />
    	<form:input id="user-form-username" path="password" />
    	<input id="user-register-confirmpassword" name="confirmPassword" />
    ...
    Code:
    	@RequestMapping("save")
    	public String register(@RequestParam(value = "to", required = false) String to, @ModelAttribute("pojo")
    			ProfileAdminOrganization pojo, BindingResult result, SessionStatus status, HttpServletRequest httpServletRequest, Model model) {
    		String confirmPassword = httpServletRequest.getParameter("confirmPassword");
    		model.addAttribute("confirmPassword", confirmPassword);
    		return requestUri + "/register";
    	}
    Any ideas?

  • #2
    if you are using JSTL you can write:

    <input id="user-register-confirmpassword" name="confirmPassword" value="${confirmPassword}"/>

    This will capture the value that you are setting in controller.

    Comment


    • #3
      Nope, it didn't work.

      Code:
      <input id="user-register-confirmpassword" name="confirmPassword" value="<c:out value='${confirmPassword}' />"/>
      EDIT

      Tryed your code as well. i tought the ${} syntax was from JSP, not JSTL, or did you forget c:out ?
      Last edited by icetbr; Sep 4th, 2008, 06:59 AM.

      Comment


      • #4
        ${} syntax should work fine if you are using a JSP 2.0 or greater implementation. <c:out> isn't required in this case (although it still should work).

        Other than that, the code you have (I think) looks fine. You do need to supply the value attribute on the input element to get the field to repopulate.

        As an aside, is there a reason you aren't making these "password" type input fields instead of cleartext?

        Comment


        • #5
          Thanks for the answer, I think my problem is somewhere else then. Yes, there is a reason: just for testing :-) Not really necessary though, as I'm only interested in either "something" or "nothing", the content is irrelevant.

          Comment

          Working...
          X