开发者

Play! - max constraint doesn't work

I'm having a problem with my application and @Max constraint annotation.

My controller me开发者_如何学运维thod is defined like this:

public static void save(@Required @Max(255) String content)

Later in my code I have error check:

if (Validation.hasErrors()) {
    render("Foo/bar.html", content);
}

The thing is, no matter what I post in the form (if it violates or not the constraint) I'm always getting error message that Cannot be greater than 255.

This is the text I'm, using for testing, 119 characters long: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ipsum enim, rhoncus eget volutpat at, posuere non eros.

Anyone had similar problem and knows how to solve it?


It sounds like you actually wanted to use @MaxSize to ensure that the length of the input was no more than 255.

Right now you're using @Max, which tries to convert the argument to a number to make sure it's numerically less than or equal to the given value. Your text can't be converted to a number, so the validation always fails in that case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜