[hibernate-commits] Hibernate SVN: r17532 - validator/trunk/hibernate-validator/src/main/docbook/en-US/modules.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Sep 23 06:21:55 EDT 2009


Author: hardy.ferentschik
Date: 2009-09-23 06:21:55 -0400 (Wed, 23 Sep 2009)
New Revision: 17532

Modified:
   validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml
   validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml
Log:
HV-220 custom constrains changes from Gunnar

Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml	2009-09-22 17:43:48 UTC (rev 17531)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml	2009-09-23 10:21:55 UTC (rev 17532)
@@ -94,6 +94,7 @@
 import java.lang.annotation.Target;
 
 import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
 
 @Target( { METHOD, FIELD, ANNOTATION_TYPE })
 @Retention(RUNTIME)
@@ -101,9 +102,11 @@
 @Documented
 public @interface CheckCase {
 
-    String message() default "{validator.checkcase}";
+    String message() default "{com.mycompany.constraints.checkcase}";
 
     Class<?>[] groups() default {};
+
+    Class<? extends Payload>[] payload() default {};
     
     CaseMode value();
 
@@ -127,11 +130,17 @@
           default to an empty array of type
           <classname>Class&lt;?&gt;</classname>.</para>
         </listitem>
+
+        <listitem>
+          <para>an attribute "payload" that can be used by clients of the Bean
+          Validation API to asign custom payload objects to a constraint. This
+          attribute is not used by the API itself.</para>
+        </listitem>
       </itemizedlist>
 
-      <para>Besides those two mandatory attributes we add another one allowing
-      for the required case mode to be specified. The name "value" is a
-      special one, which can be omitted upon using the annotation, if it is
+      <para>Besides those three mandatory attributes we add another one
+      allowing for the required case mode to be specified. The name "value" is
+      a special one, which can be omitted upon using the annotation, if it is
       the only attribute specified, as e.g. in
       <code>@CheckCase(CaseMode.UPPER)</code>.</para>
 
@@ -227,8 +236,7 @@
 
       <para>The passed-in <classname>ConstraintValidatorContext</classname>
       could be used to raise any custom validation errors, but as we are fine
-      with the default behavior, we can ignore that parameter for now (TODO
-      GM: example for usage).</para>
+      with the default behavior, we can ignore that parameter for now.</para>
     </section>
 
     <section id="validator-customconstraints-errormessage" revision="1">
@@ -241,7 +249,7 @@
       <filename>src/main/resources</filename> with the following
       content:</para>
 
-      <programlisting>validator.checkcase=Case mode must be {value}.</programlisting>
+      <programlisting>com.mycompany.constraints.checkcase=Case mode must be {value}.</programlisting>
 
       <para>If a validation error occurs, the validation runtime will use the
       default value, that we specified for the message attribute of the
@@ -370,6 +378,7 @@
 import java.lang.annotation.Target;
 
 import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
@@ -382,10 +391,12 @@
 @Documented
 public @interface ValidLicensePlate {
 
-    String message() default "{validator.validlicenseplate}";
+    String message() default "{com.mycompany.constraints.validlicenseplate}";
 
     Class&lt;?&gt;[] groups() default {};
 
+    Class&lt;? extends Payload&gt;[] payload() default {};
+
 }</programlisting>
 
     <para>To do so, we just have to annotate the constraint declaration with
@@ -396,8 +407,6 @@
     declare a validator within the <classname>@Constraint </classname>meta
     annotation.</para>
 
-    <para>TODO GM: Specifying no validator does not yet work.</para>
-
     <para>Using the new compound constraint at the
     <property>licensePlate</property> field now is fully equivalent to the
     previous version, where we declared the three constraints directly at the
@@ -427,10 +436,12 @@
 @ReportAsSingleViolation
 public @interface ValidLicensePlate {
 
-    String message() default "{validator.validlicenseplate}";
+    String message() default "{com.mycompany.constraints.validlicenseplate}";
 
     Class&lt;?&gt;[] groups() default {};
 
+    Class&lt;? extends Payload&gt;[] payload() default {};
+
 }</programlisting>
   </section>
 </chapter>

Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml	2009-09-22 17:43:48 UTC (rev 17531)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml	2009-09-23 10:21:55 UTC (rev 17532)
@@ -261,7 +261,7 @@
       <property>rentalStation</property> is validated, but also the constraint
       on <property>manufacturer</property> from the parent class.</para>
 
-      <para>The same would holds true, if <classname>Car</classname> were an
+      <para>The same would hold true, if <classname>Car</classname> were an
       interface implemented by <classname>RentalCar</classname>.</para>
 
       <para>Constraint annotations are aggregated if methods are overridden.
@@ -372,12 +372,8 @@
 import java.util.List;
 
 import javax.validation.Valid;
-import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
 
-import org.hibernate.validator.constraints.NotEmpty;
-
 public class Car {
 
     @NotNull



More information about the hibernate-commits mailing list