-
Dec 12th, 2012, 01:26 AM
#1
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");
}
-
Dec 12th, 2012, 02:22 AM
#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.
-
Dec 12th, 2012, 04:38 AM
#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" />
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules