开发者

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜