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.
Server side validation for notNull attribute doesn't work. On save user is created without valida开发者_StackOverflow中文版tion error.
Am I missing something over here ??
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)); }
Another solution is to use this JSR-303 annotation:
@javax.validation.constraints.Size(min = 1)
You can add this manually, or Roo can apply it for you via the "--sizeMin" argument of the "field" command.
精彩评论