Results 1 to 3 of 3

Thread: Form is cleared after submit

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Default Form is cleared after submit

    Hi
    I am new to spring mvc I am facing one issue once the form is submitted the older value in the form is still appearing:

    Here is my post method for the form:

    @RequestMapping(value = "/AddUser", method = RequestMethod.POST)
    public ModelAndView saveUser(User user) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date currentDate = sdf.parse(sdf.format(new Date()));
    user.setCreatDt(currentDate);
    user.setUpdDt(currentDate);
    user.setUpdBy("UBSPROD");
    user.setCreatBy("UBSPROD");
    userService.creatUser(user);
    return new ModelAndView("/AddUser.jsp", "user", new User()).addObject(
    "UserAdded", "userAdded");
    }

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Please use [ code][/code ] tags when posting code.

    Without seeing the jsp there isn't much to tell, in your jsp you should use the spring form tags to get binding, if you don't spring isn't going to help you much for clearing the form.

    Also your controller is a bit flawed. You shouldn't specify the full page but just a name and let a ViewResolver resolve the actual view. Your User attribute should be annotated with @ModelAttribute and to create the user either have a method that reacts to get and adds it to the model or create a method annotated with @ModelAttribute to create/retrieve the modelattribute.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2012
    Posts
    4

    Default

    Hi yes I am using form:form in the jsp, Here is the snap shot of my jsp:

    <form:form commandName="user">

    <form:hidden path="creatBy" />
    <form:hidden path="creatDt" />
    <p>
    <label>Name:</label>
    <form:input path="name" />
    <form:errors path="name" cssClass="error" />
    </p>
    <p>
    <label>LoginId:</label>
    <form:input path="userLogin" />
    <form:errors path="userLogin" cssClass="error" />
    </p>
    <p>
    <label>Password:</label>
    <form:input path="password" />
    <form:errors path="password" cssClass="error" />
    </p>
    <p>
    <label>EmailId:</label>
    <form:input path="email" />
    <form:errors path="email" cssClass="error" />
    </p>

    <p>
    <label>UserRole:</label>
    <form:select path="userRoleId" id="roleList">
    <form:option value="">Select</form:option>

    </form:select>

    <form:errors path="userRoleId" cssClass="error" />
    </p>
    <input type="submit" name="AddUser" value="AddUser" />

Posting Permissions

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