All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opensymphony.xwork2.validator.annotations.Validations Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.opensymphony.xwork2.validator.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 
 * 

If you want to use several annotations of the same type, these annotations must be nested within the @Validations() annotation.

* * *

Annotation usage:

* * *

Used at METHOD level.

* * *

Annotation parameters:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Parameter Required Notes
requiredFields no Add list of RequiredFieldValidators
customValidators no Add list of CustomValidators
conversionErrorFields no Add list of ConversionErrorFieldValidators
dateRangeFields no Add list of DateRangeFieldValidators
emails no Add list of EmailValidators
fieldExpressions no Add list of FieldExpressionValidators
intRangeFields no Add list of IntRangeFieldValidators
requiredStrings no Add list of RequiredStringValidators
stringLengthFields no Add list of StringLengthFieldValidators
urls no Add list of UrlValidators
visitorFields no Add list of VisitorFieldValidators
regexFields no Add list of RegexFieldValidator
expressions no Add list of ExpressionValidator
* * *

Example code:

* *
 * 
 * @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}.")},
 *           longRangeFields =
 *                   { @LongRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
 *           shortRangeFields =
 *                   { @ShortRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "shortfield", min = "1", max = "128", 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;
 *   }
 * 
 * 
* * @author jepjep * @author Rainer Hermanns */ @Target( { ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface Validations { /** * Custom Validation rules. * * @return custom validators */ CustomValidator[] customValidators() default {}; ConversionErrorFieldValidator[] conversionErrorFields() default {}; DateRangeFieldValidator[] dateRangeFields() default {}; EmailValidator[] emails() default {}; CreditCardValidator[] creditCards() default {}; FieldExpressionValidator[] fieldExpressions() default {}; IntRangeFieldValidator[] intRangeFields() default {}; LongRangeFieldValidator[] longRangeFields() default {}; RequiredFieldValidator[] requiredFields() default {}; RequiredStringValidator[] requiredStrings() default {}; StringLengthFieldValidator[] stringLengthFields() default {}; UrlValidator[] urls() default {}; ConditionalVisitorFieldValidator[] conditionalVisitorFields() default {}; VisitorFieldValidator[] visitorFields() default {}; RegexFieldValidator[] regexFields() default {}; ExpressionValidator[] expressions() default {}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy