[hibernate-commits] Hibernate SVN: r17481 - validator/trunk/hibernate-validator/src/main/docbook/en-US/modules.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Sep 4 15:14:12 EDT 2009
Author: hardy.ferentschik
Date: 2009-09-04 15:14:11 -0400 (Fri, 04 Sep 2009)
New Revision: 17481
Modified:
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/integration.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/xmlconfiguration.xml
Log:
HV-220
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/integration.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/integration.xml 2009-09-04 14:31:32 UTC (rev 17480)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/integration.xml 2009-09-04 19:14:11 UTC (rev 17481)
@@ -103,7 +103,7 @@
</event>
</hibernate-configuration></programlisting>
</section>
-
+<!--
<section id="validator-checkconstraints-orm-jpaevent">
<title>Java Persistence event-based validation</title>
@@ -133,8 +133,8 @@
reflect the constraints.</para>
</note></para>
</section>
+ -->
</section>
-
<section>
<title>Presentation layer validation</title>
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-04 14:31:32 UTC (rev 17480)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml 2009-09-04 19:14:11 UTC (rev 17481)
@@ -271,8 +271,7 @@
<example>
<title>Class Person</title>
- <programlisting>
-package com.mycompany;
+ <programlisting>package com.mycompany;
import javax.validation.constraints.NotNull;
@@ -743,8 +742,9 @@
<classname>DriverChecks</classname> and last but not least
<property>Car.passedVehicleInspection</property> belongs to the group
<classname>CarChecks</classname>. The following example shows how passing
- different group combinations to the Validator.validate method result in
- different validation results.<example>
+ different group combinations to the
+ <methodname>Validator.validate</methodname> method result in different
+ validation results.<example>
<title>Drive away</title>
<programlisting>public class GroupTest {
@@ -789,8 +789,25 @@
assertEquals( 0, validator.validate( car, Default.class, CarChecks.class, DriverChecks.class ).size() );
}
}</programlisting>
- </example></para>
+ </example>First we create a car and validate it using no explicit group.
+ There are no validation errors, even though the property
+ <property>passedVehicleInspection</property> is false. However, the
+ constraint defined on this property does not belong to the default
+ group.</para>
+ <para>Next we just validate the <classname>CarChecks</classname> group
+ which will fail until we make sure that the case passes the vehicle
+ inspection.</para>
+
+ <para>When we then add a driver to the car and validate against
+ <classname>DriverChecks</classname> we get again a constraint violation
+ due to the fact that the driver has not yet passed the driving test. Only
+ after setting <property>passedDrivingTest</property> to true the
+ validation against <classname>DriverChecks</classname> will pass.</para>
+
+ <para>Last but not least, we show that all constraints are passing by
+ validating against all defined groups.</para>
+
<section revision="1">
<title>Group sequences</title>
@@ -873,7 +890,7 @@
<classname>BigInteger</classname>, <classname>String</classname>,
<classname>byte</classname>, <classname>short</classname>,
<classname>int</classname>, <classname>long</classname> and the
- respective warppers of the primtive types. </entry>
+ respective warppers of the primtive types.</entry>
<entry>The annotated element must be a number whose value must be
lower or equal to the specified maximum. The parameter value is
@@ -913,7 +930,7 @@
<classname>BigInteger</classname>, <classname>String</classname>,
<classname>byte</classname>, <classname>short</classname>,
<classname>int</classname>, <classname>long</classname> and the
- respective warppers of the primtive types. </entry>
+ respective warppers of the primtive types.</entry>
<entry>Check whether the property is a number having up to
<literal>integer</literal> digits and <literal>fraction</literal>
@@ -1007,7 +1024,7 @@
<entry>field/property. Needs to be a string.</entry>
<entry>Check if the string is not <constant>null</constant> nor
- empty. </entry>
+ empty.</entry>
<entry>Column(s) are not null (for String).</entry>
</row>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/xmlconfiguration.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/xmlconfiguration.xml 2009-09-04 14:31:32 UTC (rev 17480)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/xmlconfiguration.xml 2009-09-04 19:14:11 UTC (rev 17481)
@@ -30,7 +30,17 @@
<section>
<title><filename>validation.xml</filename></title>
- <para><mediaobject>
+ <para>The key to enable XML configuration for Hibernate Validator the the
+ file <filename>validation.xml</filename>. If this file exists in the
+ classpath the configuration specified in it will be considered when the
+ <classname>ValidationFactory</classname> gets created. <warning>
+ <para>There can only be one <filename>validation.xml</filename> in the
+ classpath. If more than one is found an exception is thrown.</para>
+ </warning>The <xref linkend="image-validation-configuration" /> shows a
+ model view of the validation-configuration xsd and <xref
+ linkend="example-validation-xml" /> shows a valid
+ <filename>validation.xml</filename>. Let's have a look at the different
+ settings. <mediaobject id="image-validation-configuration">
<imageobject role="fo">
<imagedata align="center" fileref="validation-configuration-1.0.png"
scalefit="1" />
@@ -44,6 +54,21 @@
<caption><para>Model view
validation-configuration-1.0.xsd</para></caption>
</mediaobject></para>
+
+ <para></para>
+
+ <example id="example-validation-xml">
+ <title>validation.xml</title>
+
+ <programlisting><?xml version="1.0" encoding="UTF-8"?>
+<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <constraint-mapping>org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml</constraint-mapping>
+ <constraint-mapping>org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml</constraint-mapping>
+ <property name="javax.validation.test">foobar</property>
+</validation-config></programlisting>
+ </example>
</section>
<section>
@@ -61,6 +86,73 @@
</imageobject>
<caption><para>Model view validation-mapping-1.0.xsd</para></caption>
- </mediaobject></para>
+ </mediaobject><example>
+ <title>XML configuration of Car TODO!</title>
+
+ <programlisting><constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
+ xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <default-package>org.hibernate.jsr303.tck.tests.xmlconfiguration</default-package>
+ <bean class="User" ignore-annotations="false">
+ <class ignore-annotations="true">
+ <group-sequence>
+ <value>User</value>
+ <value>Optional</value>
+ </group-sequence>
+ <constraint annotation="org.hibernate.jsr303.tck.tests.xmlconfiguration.ConsistentUserInformation">
+ <message>Message from xml</message>
+ <groups>
+ <value>javax.validation.groups.Default</value>
+ </groups>
+ <payload>
+ <value>org.hibernate.jsr303.tck.tests.xmlconfiguration.Error</value>
+ </payload>
+ <element name="stringParam">foobar</element>
+ <element name="classParam">java.lang.String</element>
+ <element name="stringArrayParam">
+ <value>foo</value>
+ <value>bar</value>
+ </element>
+ <element name="intParam">
+ <value>42</value>
+ </element>
+ <element name="patterns">
+ <annotation>
+ <element name="regexp">myRegExp1</element>
+ </annotation>
+ <annotation>
+ <element name="regexp">myRegExp2</element>
+ </annotation>
+ </element>
+ <element name="userType">SELLER</element>
+ </constraint>
+ </class>
+ <field name="lastname">
+ <constraint annotation="javax.validation.constraints.Pattern">
+ <message>Last name has to start with with a capital letter.</message>
+ <element name="regexp">^[A-Z][a-z]+</element>
+ </constraint>
+ </field>
+ <field name="creditcard">
+ <valid/>
+ </field>
+ <getter name="firstname" ignore-annotations="true">
+ <constraint annotation="javax.validation.constraints.Size">
+ <message>Size is limited!</message>
+ <groups>
+ <value>org.hibernate.jsr303.tck.tests.xmlconfiguration.TestGroup</value>
+ <value>javax.validation.groups.Default</value>
+ </groups>
+ <element name="max">10</element>
+ </constraint>
+ </getter>
+ </bean>
+ <constraint-definition annotation="ConsistentUserInformation">
+ <validated-by include-existing-validators="false">
+ <value>org.hibernate.jsr303.tck.tests.xmlconfiguration.CustomConsistentUserValidator</value>
+ </validated-by>
+ </constraint-definition>
+</constraint-mappings></programlisting>
+ </example></para>
</section>
</chapter>
More information about the hibernate-commits
mailing list