I'm using Spring 3 Portlet MVC. Validation/binding in just MVC should be the same.
I've got just a single int
form field. When I'm doing
void doSmth(MyForm form, BindingResult bindingResult) throws ... {
int bindErrors = bindingResult.getErrorCount())
...
and submitting a field value that can't be parsed as int
this method gets executed and bindErrors
is 1. Form field value that this method receives is 0. That's great.
But creating a form just to contain a single field is not great.
I'm changing the code to:
void doSmth(@RequestParam int userId, BindingResult bindingResult) ... {
int bindErrors = bindingResult.getErrorCount())
...
and getting Portlet not available message in browser and this Exception:
org.springframework.web.portlet.FrameworkPortlet processRequest Could not complete request org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "q"
Question: is there any way to proceed with method execution and to process binding errors in it even if @RequestParam
type conversion fails? I tried making @RequestParam
not required and providing a default value to it - didn't help.