How to submit a form back to its controller?
Hi all,
I'm trying to code a small form which enables the user to add/delete an object to a list, or alternately, save all of the objects on the page. Importantly, I'm trying to accomplish all of this with one form and one controller since it seems to be a simple repetitive operation in which only the number of objects displayed varies in the end...
I've successfully coded the 'save' part of the operation, but adding and deleting of the individual objects (i.e. text input boxes of a form) are causing me a major headache.
Thus far:
I extended SimpleFormController and overrode the following methods:
Code:
public class BlockTradeEditController extends SimpleFormController{
void initBinder(HttpServletRequest request, ServletRequestDataBinder binder){
}
Object formBackingObject(HttpServletRequest request){
}
ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors){
}
ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors){
String view;
if(request.getParameter("add") != null){
//code to add another row/object here...
view = getFormView(); //name of form (this is likely my problem?)
}
else{
//plain save object + get success view code here...
view = getSuccessView(); //success view i.e. a .jsp with a list, standard fare....
}
return new ModelAndView(view, map);
}
Essentially I'm having trouble with submitting the form with the "add" parameter, and having the controller call all of it's setup methods again (i.e. showForm, formBackingObject, initBinder, etc.) since they are necessary for proper dislplay of the form...
I know this is likely a noobish mistake, but I'm just starting out in Spring and am stuck at this point. Any help would be greatly appreciated... And don't be shy about suggesting other solutions.