/
usingvalidator.pot
1715 lines (1491 loc) · 58.2 KB
/
usingvalidator.pot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2011-11-14 10:37+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <kde-i18n-doc@kde.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Tag: title
#: usingvalidator.xml:24
#, no-c-format
msgid "Validation step by step"
msgstr ""
#. Tag: para
#: usingvalidator.xml:26
#, no-c-format
msgid "In this chapter we will see in more detail how to use Hibernate Validator to validate constraints for a given entity model. We will also learn which default constraints the Bean Validation specification provides and which additional constraints are only provided by Hibernate Validator. Let's start with how to add constraints to an entity."
msgstr ""
#. Tag: title
#: usingvalidator.xml:33
#, no-c-format
msgid "Defining constraints"
msgstr ""
#. Tag: para
#: usingvalidator.xml:35
#, no-c-format
msgid "Constraints in Bean Validation are expressed via Java annotations. In this section we show how to annotate an object model with these annotations. We have to differentiate between three different type of constraint annotations - field-, property-, and class-level annotations."
msgstr ""
#. Tag: para
#: usingvalidator.xml:42
#, no-c-format
msgid "Not all constraints can be placed on all of these levels. In fact, none of the default constraints defined by Bean Validation can be placed at class level. The <classname>java.lang.annotation.Target</classname> annotation in the constraint annotation itself determines on which elements a constraint can be placed. See <xref linkend=\"validator-customconstraints\"/> for more information."
msgstr ""
#. Tag: title
#: usingvalidator.xml:51
#, no-c-format
msgid "Field-level constraints"
msgstr ""
#. Tag: para
#: usingvalidator.xml:53
#, no-c-format
msgid "Constraints can be expressed by annotating a field of a class. <xref linkend=\"example-field-level\"/> shows a field level configuration example:"
msgstr ""
#. Tag: title
#: usingvalidator.xml:58
#, no-c-format
msgid "Field level constraint"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:60
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class Car {\n"
"\n"
" @NotNull\n"
" private String manufacturer;\n"
"\n"
" @AssertTrue\n"
" private boolean isRegistered;\n"
"\n"
" public Car(String manufacturer, boolean isRegistered) {\n"
" super();\n"
" this.manufacturer = manufacturer;\n"
" this.isRegistered = isRegistered;\n"
" }\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:63
#, no-c-format
msgid "When using field level constraints field access strategy is used to access the value to be validated. This means the bean validation provider directly accesses the instance variable and does not invoke the property accessor method also if such a method exists."
msgstr ""
#. Tag: para
#: usingvalidator.xml:69
#, no-c-format
msgid "The access type (private, protected or public) does not matter."
msgstr ""
#. Tag: para
#: usingvalidator.xml:74
#, no-c-format
msgid "Static fields and properties cannot be validated."
msgstr ""
#. Tag: para
#: usingvalidator.xml:78
#, no-c-format
msgid "When validating byte code enhanced objects property level constraints should be used, because the byte code enhancing library won't be able to determine a field access via reflection."
msgstr ""
#. Tag: title
#: usingvalidator.xml:85
#, no-c-format
msgid "Property-level constraints"
msgstr ""
#. Tag: para
#: usingvalidator.xml:87
#, no-c-format
msgid "If your model class adheres to the <ulink type=\"\" url=\"http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp\">JavaBeans</ulink> standard, it is also possible to annotate the properties of a bean class instead of its fields. <xref linkend=\"example-property-level\"/> uses the same entity as in <xref linkend=\"example-field-level\"/>, however, property level constraints are used."
msgstr ""
#. Tag: para
#: usingvalidator.xml:93
#, no-c-format
msgid "The property's getter method has to be annotated, not its setter."
msgstr ""
#. Tag: title
#: usingvalidator.xml:98
#, no-c-format
msgid "Property level constraint"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:100
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.constraints.AssertTrue;\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class Car {\n"
"\n"
" private String manufacturer;\n"
"\n"
" private boolean isRegistered;\n"
" \n"
" public Car(String manufacturer, boolean isRegistered) {\n"
" super();\n"
" this.manufacturer = manufacturer;\n"
" this.isRegistered = isRegistered;\n"
" }\n"
"\n"
" @NotNull\n"
" public String getManufacturer() {\n"
" return manufacturer;\n"
" }\n"
"\n"
" public void setManufacturer(String manufacturer) {\n"
" this.manufacturer = manufacturer;\n"
" }\n"
"\n"
" @AssertTrue\n"
" public boolean isRegistered() {\n"
" return isRegistered;\n"
" }\n"
"\n"
" public void setRegistered(boolean isRegistered) {\n"
" this.isRegistered = isRegistered;\n"
" }\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:103
#, no-c-format
msgid "When using property level constraints property access strategy is used to access the value to be validated. This means the bean validation provider accesses the state via the property accessor method. One advantage of annotating properties instead of fields is that the constraints become part of the constrained type's API that way and users are aware of the existing constraints without having to examine the type's implementation."
msgstr ""
#. Tag: para
#: usingvalidator.xml:112
#, no-c-format
msgid "It is recommended to stick either to field <emphasis>or</emphasis> property annotations within one class. It is not recommended to annotate a field <emphasis>and</emphasis> the accompanying getter method as this would cause the field to be validated twice."
msgstr ""
#. Tag: title
#: usingvalidator.xml:121
#, no-c-format
msgid "Class-level constraints"
msgstr ""
#. Tag: para
#: usingvalidator.xml:124
#, no-c-format
msgid "Last but not least, a constraint can also be placed on class level. When a constraint annotation is placed on this level the class instance itself passed to the <classname>ConstraintValidator</classname>. Class level constraints are useful if it is necessary to inspect more than a single property of the class to validate it or if a correlation between different state variables has to be evaluated. In <xref linkend=\"example-class-level\"/> we add the property <property>passengers</property> to the class <classname>Car</classname>. We also add the constraint <classname>PassengerCount</classname> on the class level. We will later see how we can actually create this custom constraint (see <xref linkend=\"validator-customconstraints\"/>). For now it is enough to know that <classname>PassengerCount</classname> will ensure that there cannot be more passengers in a car than there are seats."
msgstr ""
#. Tag: title
#: usingvalidator.xml:140
#, no-c-format
msgid "Class level constraint"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:142
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.constraints.Min;\n"
"import javax.validation.constraints.NotNull;\n"
"import javax.validation.constraints.Size;\n"
"\n"
"@PassengerCount\n"
"public class Car {\n"
"\n"
" @NotNull\n"
" private String manufacturer;\n"
"\n"
" @NotNull\n"
" @Size(min = 2, max = 14)\n"
" private String licensePlate;\n"
"\n"
" @Min(2)\n"
" private int seatCount;\n"
" \n"
" private List<Person> passengers;\n"
" \n"
" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
" this.manufacturer = manufacturer;\n"
" this.licensePlate = licencePlate;\n"
" this.seatCount = seatCount;\n"
" }\n"
"\n"
" //getters and setters ...\n"
"}"
msgstr ""
#. Tag: title
#: usingvalidator.xml:147
#, no-c-format
msgid "Constraint inheritance"
msgstr ""
#. Tag: para
#: usingvalidator.xml:149
#, no-c-format
msgid "When validating an object that implements an interface or extends another class, all constraint annotations on the implemented interface and parent class apply in the same manner as the constraints specified on the validated object itself. To make things clearer let's have a look at the following example:"
msgstr ""
#. Tag: title
#: usingvalidator.xml:156
#, no-c-format
msgid "Constraint inheritance using RentalCar"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:158
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class RentalCar extends Car {\n"
"\n"
" private String rentalStation;\n"
" \n"
" public RentalCar(String manufacturer, String rentalStation) {\n"
" super(manufacturer);\n"
" this.rentalStation = rentalStation;\n"
" }\n"
" \n"
" @NotNull\n"
" public String getRentalStation() {\n"
" return rentalStation;\n"
" }\n"
"\n"
" public void setRentalStation(String rentalStation) {\n"
" this.rentalStation = rentalStation;\n"
" }\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:161
#, no-c-format
msgid "Our well-known class <classname>Car</classname> is now extended by <classname>RentalCar</classname> with the additional property <property>rentalStation</property>. If an instance of <classname>RentalCar</classname> is validated, not only the <classname>@NotNull</classname> constraint on <property>rentalStation</property> is validated, but also the constraint on <property>manufacturer</property> from the parent class."
msgstr ""
#. Tag: para
#: usingvalidator.xml:169
#, no-c-format
msgid "The same would hold true, if <classname>Car</classname> were an interface implemented by <classname>RentalCar</classname>."
msgstr ""
#. Tag: para
#: usingvalidator.xml:172
#, no-c-format
msgid "Constraint annotations are aggregated if methods are overridden. If <classname>RentalCar</classname> would override the <methodname>getManufacturer()</methodname> method from <classname>Car</classname> any constraints annotated at the overriding method would be evaluated in addition to the <classname>@NotNull</classname> constraint from the super-class."
msgstr ""
#. Tag: title
#: usingvalidator.xml:181
#, no-c-format
msgid "Object graphs"
msgstr ""
#. Tag: para
#: usingvalidator.xml:183
#, no-c-format
msgid "The Bean Validation API does not only allow to validate single class instances but also complete object graphs. To do so, just annotate a field or property representing a reference to another object with <classname>@Valid</classname>. If the parent object is validated, all referenced objects annotated with <classname>@Valid</classname> will be validated as well (as will be their children etc.). See <xref linkend=\"example-car-with-driver\"/>."
msgstr ""
#. Tag: title
#: usingvalidator.xml:192
#, no-c-format
msgid "Class Person"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:194
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class Person {\n"
"\n"
" @NotNull\n"
" private String name;\n"
" \n"
" public Person(String name) {\n"
" super();\n"
" this.name = name;\n"
" }\n"
"\n"
" public String getName() {\n"
" return name;\n"
" }\n"
"\n"
" public void setName(String name) {\n"
" this.name = name;\n"
" }\n"
"}"
msgstr ""
#. Tag: title
#: usingvalidator.xml:198
#, no-c-format
msgid "Adding a driver to the car"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:200
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import javax.validation.Valid;\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class Car {\n"
"\n"
" @NotNull\n"
" @Valid\n"
" private Person driver;\n"
" \n"
" public Car(Person driver) {\n"
" this.driver = driver;\n"
" }\n"
"\n"
" //getters and setters ...\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:203
#, no-c-format
msgid "If an instance of <classname>Car</classname> is validated, the referenced <classname>Person</classname> object will be validated as well, as the <property>driver</property> field is annotated with <classname>@Valid</classname>. Therefore the validation of a <classname>Car</classname> will fail if the <property>name</property> field of the referenced <classname>Person</classname> instance is <code>null</code>."
msgstr ""
#. Tag: para
#: usingvalidator.xml:211
#, no-c-format
msgid "Object graph validation also works for collection-typed fields. That means any attributes that"
msgstr ""
#. Tag: para
#: usingvalidator.xml:216
#, no-c-format
msgid "are arrays"
msgstr ""
#. Tag: para
#: usingvalidator.xml:220
#, no-c-format
msgid "implement <classname>java.lang.Iterable</classname> (especially <classname>Collection</classname>, <classname>List</classname> and <classname>Set</classname>)"
msgstr ""
#. Tag: para
#: usingvalidator.xml:226
#, no-c-format
msgid "implement <classname>java.util.Map</classname>"
msgstr ""
#. Tag: para
#: usingvalidator.xml:230
#, no-c-format
msgid "can be annotated with <classname>@Valid</classname>, which will cause each contained element to be validated, when the parent object is validated."
msgstr ""
#. Tag: title
#: usingvalidator.xml:235
#, no-c-format
msgid "Car with a list of passengers"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:237
#, no-c-format
msgid ""
"package com.mycompany;\n"
"\n"
"import java.util.ArrayList;\n"
"import java.util.List;\n"
"\n"
"import javax.validation.Valid;\n"
"import javax.validation.constraints.NotNull;\n"
"\n"
"public class Car {\n"
"\n"
" @NotNull\n"
" @Valid\n"
" private List<Person> passengers = new ArrayList<Person>();\n"
"\n"
" public Car(List<Person> passengers) {\n"
" this.passengers = passengers;\n"
" }\n"
"\n"
" //getters and setters ...\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:240
#, no-c-format
msgid "If a <classname>Car</classname> instance is validated, a <classname>ConstraintValidation</classname> will be created, if any of the <classname>Person</classname> objects contained in the <property>passengers</property> list has a <code>null</code> name."
msgstr ""
#. Tag: para
#: usingvalidator.xml:244
#, no-c-format
msgid "<classname>null</classname> values are getting ignored when validating object graphs."
msgstr ""
#. Tag: title
#: usingvalidator.xml:251
#, no-c-format
msgid "Validating constraints"
msgstr ""
#. Tag: para
#: usingvalidator.xml:253
#, no-c-format
msgid "The <classname>Validator</classname> interface is the main entry point to Bean Validation. In <xref linkend=\"section-validator-instance\"/> we will first show how to obtain an <classname>Validator</classname> instance. Afterwards we will learn how to use the different methods of the <classname>Validator</classname> interface."
msgstr ""
#. Tag: title
#: usingvalidator.xml:260
#, no-c-format
msgid "Obtaining a <classname>Validator</classname> instance"
msgstr ""
#. Tag: para
#: usingvalidator.xml:262
#, no-c-format
msgid "The first step towards validating an entity instance is to get hold of a <classname>Validator</classname> instance. The road to this instance leads via the <classname>Validation</classname> class and a <classname>ValidatorFactory</classname>. The easiest way is to use the static <methodname>Validation.buildDefaultValidatorFactory()</methodname> method:"
msgstr ""
#. Tag: title
#: usingvalidator.xml:271
#, no-c-format
msgid "Validation.buildDefaultValidatorFactory()"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:273
#, no-c-format
msgid ""
"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
"Validator validator = factory.getValidator();"
msgstr ""
#. Tag: para
#: usingvalidator.xml:276
#, no-c-format
msgid "For other ways of obtaining a Validator instance see <xref linkend=\"validator-bootstrapping\"/>. For now we just want to see how we can use the <classname>Validator</classname> instance to validate entity instances."
msgstr ""
#. Tag: title
#: usingvalidator.xml:283
#, no-c-format
msgid "Validator methods"
msgstr ""
#. Tag: para
#: usingvalidator.xml:285
#, no-c-format
msgid "The <classname>Validator</classname> interface contains three methods that can be used to either validate entire entities or just a single properties of the entity."
msgstr ""
#. Tag: para
#: usingvalidator.xml:289
#, no-c-format
msgid "All three methods return a <classname>Set<ConstraintViolation></classname>. The set is empty, if the validation succeeds. Otherwise a <classname>ConstraintViolation</classname> instance is added for each violated constraint."
msgstr ""
#. Tag: para
#: usingvalidator.xml:295
#, no-c-format
msgid "All the validation methods have a var-args parameter which can be used to specify, which validation groups shall be considered when performing the validation. If the parameter is not specified the default validation group (<classname>javax.validation.groups.Default</classname>) will be used. We will go into more detail on the topic of validation groups in"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:304
#, no-c-format
msgid "validate"
msgstr ""
#. Tag: para
#: usingvalidator.xml:306
#, no-c-format
msgid "Use the <methodname>validate()</methodname> method to perform validation of all constraints of a given entity instance (see <xref linkend=\"example-validator-validate\"/> )."
msgstr ""
#. Tag: title
#: usingvalidator.xml:311
#, no-c-format
msgid "Usage of <methodname>Validator.validate()</methodname>"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:314
#, no-c-format
msgid ""
"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
"Validator validator = factory.getValidator();\n"
"\n"
"Car car = new Car(null);\n"
"\n"
"Set<ConstraintViolation<Car>> constraintViolations = validator.validate(car);\n"
"\n"
"assertEquals(1, constraintViolations.size());\n"
"assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:319
#, no-c-format
msgid "validateProperty"
msgstr ""
#. Tag: para
#: usingvalidator.xml:321
#, no-c-format
msgid "With help of the <methodname>validateProperty()</methodname> a single named property of a given object can be validated. The property name is the JavaBeans property name."
msgstr ""
#. Tag: title
#: usingvalidator.xml:326
#, no-c-format
msgid "Usage of <methodname>Validator.validateProperty()</methodname>"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:329
#, no-c-format
msgid ""
"Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n"
"\n"
"Car car = new Car(null);\n"
"\n"
"Set<ConstraintViolation<Car>> constraintViolations = validator.validateProperty(car, \"manufacturer\");\n"
"\n"
"assertEquals(1, constraintViolations.size());\n"
"assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
msgstr ""
#. Tag: para
#: usingvalidator.xml:332
#, no-c-format
msgid "<methodname>Validator.validateProperty</methodname> is for example used in the integration of Bean Validation into JSF 2 (see <xref linkend=\"section-presentation-layer\"/>)."
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:338
#, no-c-format
msgid "validateValue"
msgstr ""
#. Tag: para
#: usingvalidator.xml:340
#, no-c-format
msgid "Using the <methodname>validateValue() </methodname>method you can check, whether a single property of a given class can be validated successfully, if the property had the specified value:"
msgstr ""
#. Tag: title
#: usingvalidator.xml:345
#, no-c-format
msgid "Usage of <methodname>Validator.validateValue()</methodname>"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:348
#, no-c-format
msgid ""
"Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n"
"\n"
"Set<ConstraintViolation<Car>> constraintViolations = validator.validateValue(Car.class, \"manufacturer\", null);\n"
"\n"
"assertEquals(1, constraintViolations.size());\n"
"assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
msgstr ""
#. Tag: para
#: usingvalidator.xml:352
#, no-c-format
msgid "<classname>@Valid</classname> is not honored by <methodname>validateProperty()</methodname> or <methodname>validateValue()</methodname>."
msgstr ""
#. Tag: title
#: usingvalidator.xml:360
#, no-c-format
msgid "<classname>ConstraintViolation</classname> methods"
msgstr ""
#. Tag: para
#: usingvalidator.xml:362
#, no-c-format
msgid "Now it is time to have a closer look at what a <classname>ConstraintViolation</classname>. Using the different methods of <classname>ConstraintViolation</classname> a lot of useful information about the cause of the validation failure can be determined. <xref linkend=\"table-constraint-violation\"/> gives an overview of these methods:"
msgstr ""
#. Tag: title
#: usingvalidator.xml:370
#, no-c-format
msgid "The various <classname>ConstraintViolation</classname> methods"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:376
#, no-c-format
msgid "Method"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:378
#, no-c-format
msgid "Usage"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:380
#, no-c-format
msgid "Example (referring to <xref linkend=\"example-validator-validate\"/>)"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:387
#, no-c-format
msgid "getMessage()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:389
#, no-c-format
msgid "The interpolated error message."
msgstr ""
#. Tag: entry
#: usingvalidator.xml:391
#, no-c-format
msgid "may not be null"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:395
#, no-c-format
msgid "getMessageTemplate()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:397
#, no-c-format
msgid "The non-interpolated error message."
msgstr ""
#. Tag: entry
#: usingvalidator.xml:399
#, no-c-format
msgid "{javax.validation.constraints.NotNull.message}"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:403
#, no-c-format
msgid "getRootBean()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:405
#, no-c-format
msgid "The root bean being validated."
msgstr ""
#. Tag: entry
#: usingvalidator.xml:407 usingvalidator.xml:425
#, no-c-format
msgid "<entry>car</entry>"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:411
#, no-c-format
msgid "getRootBeanClass()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:413
#, no-c-format
msgid "The class of the root bean being validated."
msgstr ""
#. Tag: entry
#: usingvalidator.xml:415
#, no-c-format
msgid "Car.class"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:419
#, no-c-format
msgid "getLeafBean()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:421
#, no-c-format
msgid "If a bean constraint, the bean instance the constraint is applied on. If a property constraint, the bean instance hosting the property the constraint is applied on."
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:429
#, no-c-format
msgid "getPropertyPath()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:431
#, no-c-format
msgid "The property path to the value from root bean."
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:437
#, no-c-format
msgid "getInvalidValue()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:439
#, no-c-format
msgid "The value failing to pass the constraint."
msgstr ""
#. Tag: entry
#: usingvalidator.xml:441
#, no-c-format
msgid "passengers"
msgstr ""
#. Tag: methodname
#: usingvalidator.xml:445
#, no-c-format
msgid "getConstraintDescriptor()"
msgstr ""
#. Tag: entry
#: usingvalidator.xml:447
#, no-c-format
msgid "Constraint metadata reported to fail."
msgstr ""
#. Tag: title
#: usingvalidator.xml:457
#, no-c-format
msgid "Message interpolation"
msgstr ""
#. Tag: para
#: usingvalidator.xml:459
#, no-c-format
msgid "As we will see in <xref linkend=\"validator-customconstraints\"/> each constraint definition must define a default message descriptor. This message can be overridden at declaration time using the <methodname>message</methodname> attribute of the constraint. You can see this in <xref linkend=\"example-driver\"/>. This message descriptors get interpolated when a constraint validation fails using the configured <classname>MessageInterpolator</classname>. The interpolator will try to resolve any message parameters, meaning string literals enclosed in braces. In order to resolve these parameters Hibernate Validator's default <classname>MessageInterpolator</classname> first recursively resolves parameters against a custom <classname>ResourceBundle</classname> called <filename>ValidationMessages.properties</filename> at the root of the classpath (It is up to you to create this file). If no further replacements are possible against the custom bundle the default <classname>ResourceBundle</classname> under <filename>/org/hibernate/validator/ValidationMessages.properties</filename> gets evaluated. If a replacement occurs against the default bundle the algorithm looks again at the custom bundle (and so on). Once no further replacements against these two resource bundles are possible remaining parameters are getting resolved against the attributes of the constraint to be validated."
msgstr ""
#. Tag: para
#: usingvalidator.xml:482
#, no-c-format
msgid "Since the braces { and } have special meaning in the messages they need to be escaped if they are used literally. The following The following rules apply:"
msgstr ""
#. Tag: para
#: usingvalidator.xml:486
#, no-c-format
msgid "\\{ is considered as the literal {"
msgstr ""
#. Tag: para
#: usingvalidator.xml:490
#, no-c-format
msgid "\\} is considered as the literal }"
msgstr ""
#. Tag: para
#: usingvalidator.xml:494
#, no-c-format
msgid "\\\\ is considered as the literal \\"
msgstr ""
#. Tag: para
#: usingvalidator.xml:498
#, no-c-format
msgid "If the default message interpolator does not fit your requirements it is possible to plug a custom <classname>MessageInterpolator</classname> when the <classname>ValidatorFactory</classname> gets created. This can be seen in <xref linkend=\"validator-bootstrapping\"/>."
msgstr ""
#. Tag: title
#: usingvalidator.xml:507
#, no-c-format
msgid "Validating groups"
msgstr ""
#. Tag: para
#: usingvalidator.xml:509
#, no-c-format
msgid "Groups allow you to restrict the set of constraints applied during validation. This makes for example wizard like validation possible where in each step only a specified subset of constraints get validated. The groups targeted are passed as var-args parameters to <methodname>validate</methodname>, <methodname>validateProperty</methodname> and <methodname>validateValue</methodname>. Let's have a look at an extended <classname>Car</classname> with <classname>Driver</classname> example. First we have the class <classname>Person</classname> (<xref linkend=\"example-person\"/>) which has a <classname>@NotNull </classname>constraint on <property>name</property>. Since no group is specified for this annotation its default group is <classname>javax.validation.groups.Default</classname>."
msgstr ""
#. Tag: para
#: usingvalidator.xml:524
#, no-c-format
msgid "When more than one group is requested, the order in which the groups are evaluated is not deterministic. If no group is specified the default group <classname>javax.validation.groups.Default</classname> is assumed."
msgstr ""
#. Tag: title
#: usingvalidator.xml:531
#, no-c-format
msgid "Person"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:533
#, no-c-format
msgid ""
"public class Person {\n"
" @NotNull\n"
" private String name;\n"
"\n"
" public Person(String name) {\n"
" this.name = name;\n"
" }\n"
" // getters and setters ...\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:536
#, no-c-format
msgid "Next we have the class <classname>Driver</classname> (<xref linkend=\"example-driver\"/>) extending <classname>Person</classname>. Here we are adding the properties <property>age</property> and <property>hasDrivingLicense</property>. In order to drive you must be at least 18 (<classname>@Min(18)</classname>) and you must have a driving license (<classname>@AssertTrue</classname>). Both constraints defined on these properties belong to the group <classname>DriverChecks</classname>. As you can see in <xref linkend=\"example-group-interfaces\"/> the group <classname>DriverChecks</classname> is just a simple tagging interface. Using interfaces makes the usage of groups type safe and allows for easy refactoring. It also means that groups can inherit from each other via class inheritance."
msgstr ""
#. Tag: title
#: usingvalidator.xml:550
#, no-c-format
msgid "Driver"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:552
#, no-c-format
msgid ""
"public class Driver extends Person {\n"
" @Min(value = 18, message = \"You have to be 18 to drive a car\", groups = DriverChecks.class)\n"
" public int age;\n"
"\n"
" @AssertTrue(message = \"You first have to pass the driving test\", groups = DriverChecks.class)\n"
" public boolean hasDrivingLicense;\n"
"\n"
" public Driver(String name) {\n"
" super( name );\n"
" }\n"
"\n"
" public void passedDrivingTest(boolean b) {\n"
" hasDrivingLicense = b;\n"
" }\n"
"\n"
" public int getAge() {\n"
" return age;\n"
" }\n"
"\n"
" public void setAge(int age) {\n"
" this.age = age;\n"
" }\n"
"}"
msgstr ""
#. Tag: title
#: usingvalidator.xml:556
#, no-c-format
msgid "Group interfaces"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:558
#, no-c-format
msgid ""
"public interface DriverChecks {\n"
"}\n"
"\n"
"public interface CarChecks {\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:561
#, no-c-format
msgid "Last but not least we add the property <property>passedVehicleInspection</property> to the <classname>Car</classname> class (<xref linkend=\"example-car\"/>) indicating whether a car passed the road worthy tests."
msgstr ""
#. Tag: title
#: usingvalidator.xml:567
#, no-c-format
msgid "<title>Car</title>"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:569
#, no-c-format
msgid ""
"public class Car {\n"
" @NotNull\n"
" private String manufacturer;\n"
"\n"
" @NotNull\n"
" @Size(min = 2, max = 14)\n"
" private String licensePlate;\n"
"\n"
" @Min(2)\n"
" private int seatCount;\n"
"\n"
" @AssertTrue(message = \"The car has to pass the vehicle inspection first\", groups = CarChecks.class)\n"
" private boolean passedVehicleInspection;\n"
"\n"
" @Valid\n"
" private Driver driver;\n"
"\n"
" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
" this.manufacturer = manufacturer;\n"
" this.licensePlate = licencePlate;\n"
" this.seatCount = seatCount;\n"
" }\n"
"}"
msgstr ""
#. Tag: para
#: usingvalidator.xml:572
#, no-c-format
msgid "Overall three different groups are used in our example. <property>Person.name</property>, <property>Car.manufacturer</property>, <property>Car.licensePlate</property> and <property>Car.seatCount</property> all belong to the <classname>Default</classname> group. <property>Driver.age</property> and <property>Driver.hasDrivingLicense</property> belong to <classname>DriverChecks</classname> and last but not least <property>Car.passedVehicleInspection</property> belongs to the group <classname>CarChecks</classname>. <xref linkend=\"example-drive-away\"/> shows how passing different group combinations to the <methodname>Validator.validate</methodname> method result in different validation results."
msgstr ""
#. Tag: title
#: usingvalidator.xml:586
#, no-c-format
msgid "Drive away"
msgstr ""
#. Tag: programlisting
#: usingvalidator.xml:588
#, no-c-format
msgid ""
"public class GroupTest {\n"
"\n"
" private static Validator validator;\n"
"\n"
" @BeforeClass\n"
" public static void setUp() {\n"