Results 1 to 5 of 5

Thread: Field return empty after form validation error

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Norwalk, CT USA
    Posts
    27

    Default

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

  3. #3

    Default

    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 at 06:59 AM.

  4. #4
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    ${} 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?
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  5. #5

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •