I am new bee to SpringMVC and trying to implement this example in SpringMVC3. http://www.mkyong.com/spring-mvc/spring-mvc-handling-multipage-forms-with-abstractwizardformcontroller/ When I submit first Jsp I am able to go to next Jsp but after submitting the second Jsp it is redirecting back to first Jsp with a new Jsp(empty values). Please suggest with comments to make it more clear for me to understand.
Project
@Id
@Column(name="PROJECT_ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private int projectId;
@Column(name="PROJECT_NAME")
private String projectName;
@Column(name="LOCATION")
private String location;
@Column(name="DESCRIPTION")
private String description;
@Column(name="DEV_TYPE")
private String developmentType;
ProjectService
public void addProject(Project project);
ProjectServiceImpl
@Autowired
private ProjectDao projectDao;
public void addProject(Project project) {
projectDao.addProject(project);
}
ProjectDao
public void addProject(Project project);
ProjectDaoImpl
public void addProject(Project project) {
getCurrentSession().save(project);
}
ProjectController
@RequestMapping(value = "/addProject.htm", method = RequestMethod.GET)
public ModelAndView reportForm(ModelMap model, HttpServletRequest request,
Project project) {
model.addAttribute("project", project);
ModelAndView mav = new ModelAndView("add");
return mav;
}
@RequestMapping(value = "/addProject.htm", method = RequestMethod.POST)
public ModelAndView addConfirm(@ModelAttribute("project") Project project,
BindingResult result, ModelMap model, SessionStatus status, HttpServletRequest request) {
HttpSession session = request.getSession();
validator.validateProject(project, result);
if (result.hasErrors()) {
return new ModelAndView("addProject");
} else if (project.getDescription() == null) {
//return the form that will set field two's value
return new ModelAndView("addProjectExt");
} //and so on for all the other field that need to be set...
else{
model.addAttribute("project", project);
projectService.addProject(project);
return "redirect:listProject";
}
}
JSP1 addProject.jsp
<form:form method="POST" modelAttribute="project" action="addProject.htm" >
<div class="input">
<form:label path="projectName" type="text" value="" >Project Name :*</form:label>
<form:input path="projectName"/>
</div>
<div class="input">
<form:label path="location" type="text" value="" >Location :</form:label>
<form:input path="location"/>
</div>
</form:form>
JSP2 addProjectExt.jsp
<form:form method="POST" modelAttribute="project" action="addProject.htm" >
<div class="input">
<form:label path="description" type="text" value="" >Description :*</form:label>
<form:input path="description"/>
</div>
<div class="input">
<form:label path="developmentType" type="text" value="" >Development Type :</form:label>
<form:input path="developmentType"/>
</div>
</form:form>