|
|
multiple form-submit-actions pattern
In a jsp-form a want to edit a persons data, including uploading a picture.
This needs 3 actions to be distinguished... save, addImage, cancel
1. Is there a more elegant way to distinguish the buttons without loosing the entered form data?
2. Even more requestParams will be needed in case of image-buttons (save.x, cancel.x, addImage.x)
@RequestMapping(method = RequestMethod.POST)
public String processSubmit( @ModelAttribute(quot;accountquot;) Person person, @RequestParam(quot;imagequot;) MultipartFile image, BindingResult result, SessionStatusstatus, @RequestParam(required=false,value=quot;savequot;)String save, @RequestParam(required=false,value=quot;cancelquot;)String cancel, @RequestParam(required=false,value=quot;addImagequot;)Stri ng addImage)
{ if (save != null) {...} else if (cancel != null) {...} else if (addImage != null) {...} else throw new IllegalStateException(...)
i did not try it out by myself but if i read the api doc correctly something like
@RequestMapping(method = RequestMethod.POST, params = quot;value=savequot;)
public String processSubmit(
should work.
check here
sp...stMapping.html
and here
story/vpta2Ro_lAQZFEYv
So when using @RequestMapping at the type level, method-level annotations will 'narrow' the mapping for the specific handler methods. @RequestMapping allows for specifying from request methods (e.g. method = RequestMapping.GET) or specific request parameters (e.g. params = quot;action=savequot;), all narrowing the type-level mapping for specific methods. Alternatively, @RequestMapping at the type level can also be combined with a good old Controller interface implementation - such as a SimpleFormController or MultiActionController. |
|