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

de.knightsoftnet.validators.client.GwtValidation Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2010 Google Inc. Copyright 2016 Manfred Tremmel
 *
 * Licensed 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 de.knightsoftnet.validators.client;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import jakarta.validation.groups.Default;

/**
 * Annotates a {@code jakarta.validation.Validator} explicitly listing the classes that can be
 * validated in GWT.
 * 

* Define the Validator you want, explicitly listing the classes and groups you want to validate. *

* *
 * @GwtValidation(value = {MyBean.class, MyOther.class}, 
* groups = {Default.class, OtherGroup.class}) * public interface MyValidator extends jakarta.validation.Validator { * } *
* *

* Create and use the validator. *

* *
 * MyValidator validator = new MyValidatorImpl();
 * MyBean bean = new MyBean();
 * ...
 * Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
 * 
* *

* You must list all validation groups you are using (as well as groups making up a group * sequence)– unless you are only using the Default group, in which case you may omit the * "groups" field of the {@link GwtValidation} annotation. *

* *

* NOTE: Validation is done using only the Constraints found on the Classes listed in the * annotation. If you have *

* *
 * class MyBean {
 *   @Null
 *   String getName() {
 *     return name;
 *   }
 * }
 *
 *
 * class MySubBean extends MyBean {
 *   @Size(min = 5)
 *   String getName() {
 *     return super.getName();
 *   }
 * }
 * 
* *

* And then create your {@link jakarta.validation.ValidatorFactory ValidatorFactory} using *

* *
 * @GwtValidation(MyBean.class, MyOther.class)}
 * 
* *

* but call validator with the subclass like *

* *
 * MySubBean bean = new MySubBean();
 * Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
 * 
* *

* The {@code Size} constraint will not be validated. *

* *

* Instead make sure you list the all BeanTypes that will be directly validated in the * {@link GwtValidation} annotation. *

* * */ @Documented @Target(TYPE) @Retention(SOURCE) public @interface GwtValidation { /** * The list of Groups which can be processed by the annotated {@code Validator}. The default value * is {@link Default}. An empty array is illegal. * * @return array of classes */ Class[] groups() default {Default.class}; /** * The list of Classes which can be validated by the annotated {@code Validator}. * * @return array of classes */ Class[] value(); /** * The list of Classes which can be used a reflection getter, if empty all constrained beans are * taken (autodetection). If generateReflectionGetter is set to false, no reflection getter is * generated, even for classes of this list! * * @return array of classes */ Class[] reflect() default {}; /** * force using getter for accessing field values. * * @return boolean, true when only using getter */ boolean forceUsingGetter() default false; /** * generate reflection getter for class based validation. * * @return boolean, true when generating reflection getter */ boolean generateReflectionGetter() default true; /** * generate validator factory interface to autoinclude valdator factory. * * @return boolean, true when generating interface */ boolean generateValidatorFactoryInterface() default true; /** * The list of languages to generate messages for. * * @return array of strings */ String[] languages() default {"de", "fr", "en"}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy