Announcement Announcement Module
Collapse
No announcement yet.
Form is cleared after submit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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" />

      Comment

      Working...
      X