Search code examples
javaspringvalidationspring-annotations

Spring Validation with applyIf attribute in Annotations


I've tried to set applyIf attribute on spring annotation with some custom exspression. As exampe I have a form:

class MyForm {

    @NotBlank
    private String name;
    @NotNull
    @MinSize(applyIf = "name not equals myValue", value = 1) 
    private List<String> addresses;
    ...
}

But when I try to validate form above spring perceives myValue from exspression as property. The it tries to find getters setters for it.

Also, I've tried to dig org.springmodules.validation.valang.parser.ValangParser, but unfortunatly java docs are not present for this class.

I can't find any examples with this stuff(Only really simple cases like: "name is not blank"). Will be good if you suggest some usefull documentation. Or correct my exspression for correct verifying my goals.


Solution

  • As in comment under the question, the syntax should be "name NOT EQUALS 'myValue'"

    http://www.springbyexample.org/maven/site/sbe-validation/0.92/apidocs/org/springmodules/validation/valang/ValangValidator.html