Search code examples
spring-mvcspring-roo

Spring ROO Serverside validation doesn't work


I have created a User domain with not null fields.

If i remove following javascript validation on submit.

Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));

Server side validation for notNull attribute doesn't work. On save user is created without validation error.

Am I missing something over here ??


Solution

  • 1st of all spring-roo is not to blame for this, spring by default uses java property editor for String which converts it to empty string if no value is provide.

    Springs own StringTrimmerEditor can be used inside controllers as shown below.

    @InitBinder
        public void initBinder(WebDataBinder binder) {
            binder.registerCustomEditor(String.class, new StringTrimmerEditor(Boolean.TRUE));
        }