이 annotation은 deprecated되었다. 원래의 목적(annotation validations을 제공하는 클래스의 정의)가 더 이상 필요가 없어졌기 때문이다.
Validation annotation은 Type 단위로 적용해야 한다.
@Validation()
public class SimpleAnnotationAction extends ActionSupport {
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a value for bar.")
@IntRangeFieldValidator(type = ValidatorType.FIELD, min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")
public void setBar(int bar) {
this.bar = bar;
}
public int getBar() {
return bar;
}
@Validations(
requiredFields =
{@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")},
requiredStrings =
{@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")},
emails =
{ @EmailValidator(type = ValidatorType.SIMPLE, fieldName = "emailaddress", message = "You must enter a value for email.")},
urls =
{ @UrlValidator(type = ValidatorType.SIMPLE, fieldName = "hreflocation", message = "You must enter a value for email.")},
stringLengthFields =
{@StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength="10" , maxLength = "12", fieldName = "needstringlength", message = "You must enter a stringlength.")},
intRangeFields =
{ @IntRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
dateRangeFields =
{@DateRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "datefield", min = "-1", max = "99", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
expressions = {
@ExpressionValidator(expression = "foo > 1", message = "Foo must be greater than Bar 1. Foo = ${foo}, Bar = ${bar}."),
@ExpressionValidator(expression = "foo > 2", message = "Foo must be greater than Bar 2. Foo = ${foo}, Bar = ${bar}."),
@ExpressionValidator(expression = "foo > 3", message = "Foo must be greater than Bar 3. Foo = ${foo}, Bar = ${bar}."),
@ExpressionValidator(expression = "foo > 4", message = "Foo must be greater than Bar 4. Foo = ${foo}, Bar = ${bar}."),
@ExpressionValidator(expression = "foo > 5", message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar = ${bar}.")
}
)
public String execute() throws Exception {
return SUCCESS;
}
}
하나의 클래스에 여러개의 action을 각각의 메소드로 맵핑한 상태에서, 메소드 하나라도 @Validations을 annotate한 경우, 모든 액션에 대해서 validator가 유효하게 된다. 이를 피하려면 @SkipValidation을 annotate하거나
validation 인터셉터의 validateAnnotatedMethodOnly속성을 true로 정의한다.