I was initially trying to use Spring form tags and Validation on the Spring controller to submit form data. Since I have to update only the div in JSP page I don't think I can use this technique. So I am trying to use AJAX call. Following are the snippet of the code I have so far
Main JSP page (main.JSP)
<div id="header">...</div>
<div id="content">
<div id="info1">....</info">
<div id="info2">
<%@ include file="/WEB-INF/jsp/myForm.jsp" %>
</div>
<div id="info3">...</div>
...
</div>
<div id="footer">...</div>
JSP Page (myForm.jsp)
<form:form action="/postFormData.htm" commandName="myEntryForm">
//All inputs using <form:input> tags
</form:form>
Spring MVC Controller
@RequestMapping(value = "/telephone/sendMemberEntryEmail.htm", method = RequestMethod.POST)
public ModelAndView doSomeWork(Model model, @Valid MyEntryForm myEntryForm, BindingResult result) {
if(result.hasErrors()) {
return new ModelAndView("myForm", "myEntryForm", myEntryForm);
}
return new ModelAndView("successPage");
}
So here I am trying to send response (both with error or succcess) to div named info2. Issue I am facing is since I am using action it is updating whole main page with response.
Because of that I am thinking of doing AJAX call but I am not sure how I can collect form data and send to controller. I can't send each field as parameter as I have many fields and collection of related fields. I wan to send ti using MyEntryForm object.
Please suggest.