myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Extensions/Validator/DevDoc/Drafts" by GerhardPetracek
Date Wed, 03 Mar 2010 17:51:38 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The "Extensions/Validator/DevDoc/Drafts" page has been changed by GerhardPetracek.
http://wiki.apache.org/myfaces/Extensions/Validator/DevDoc/Drafts?action=diff&rev1=15&rev2=16

--------------------------------------------------

   * @EmptyIf (see EXTVAL-75)
   * @DateRange
   * @Expression
+  * @ConstraintSource
+    * @TargetProperty
+    * @TargetPropertyId
+    * @IgnoreConstraintSource
  
  ==== Details about @Expression ====
  
@@ -23, +27 @@

  moreover, @Expression should provide an attribute which points to the expression evaluator.
so it's possible to create custom expressions by providing a custom evaluator. See also the
ReferenceResolver idea, maybe expression evaluator could build further on that basis.
  
  furthermore, it should also work for component initialization.
+ 
+ ==== Details about @ConstraintSource ====
+ It should be possible to expose constraints through DTO's.
+ 
+ Example entities:
+ {{{
+ @Entity
+ public class User extends AbstractDomainObject
+ {
+   @NotNull @Column @Size(min = 2, max = 64)
+   private String firstName;
+ 
+   @NotNull @Column @Size(min = 2, max = 64)
+   private String lastName;
+ 
+   @ManyToMany(mappedBy = "users")
+   private List<Group> groups = new ArrayList<Group>();
+   //...
+ }
+ 
+ @Entity
+ public class Group extends AbstractDomainObject
+ {
+     @NotNull @Column @Size(min = 2, max = 14)
+     private String name;
+ 
+     @ManyToMany(cascade = CascadeType.PERSIST)
+     private List<User> users = new ArrayList<User>();
+   //...
+ }
+ }}}
+ 
+ ===== Use-Case 1 =====
+ {{{
+ @ConstraintSource(User.class)
+ public class UserDTO
+ {
+   private String firstName; //mapped automatically to User#firstName
+   private String lastName;  //mapped automatically to User#lastName
+ 
+   //...
+ }
+ }}}
+ 
+ ===== Use-Case 2 =====
+ {{{
+ @ConstraintSource(User.class)
+ public class UserDTO
+ {
+   @IgnoreConstraintSource
+   @Size(min = 2, max = 32)
+   private String firstName; //no mapping - constraints of the current property are used
+ 
+   @TargetProperty("lastName")
+   private String surName;  //mapped to User#lastName
+ 
+   //...
+ }
+ }}}
+ 
+ ===== Use-Case 3 =====
+ {{{
+ @ConstraintSource(User.class)
+ public class UserDTO
+ {
+   //...
+ 
+   @ConstraintSource(Group.class)
+   private String name;  //mapped to Group#name
+ }
+ }}}
+ 
+ ===== Use-Case 4 =====
+ {{{
+ @ConstraintSource(User.class)
+ public class UserDTO
+ {
+   //...
+ 
+   @ConstraintSource(Group.class)
+   @TargetProperty("name")
+   private String defaultGroupName;  //mapped to Group#name
+ }
+ }}}
+ 
+ ===== Use-Case 5 =====
+ {{{
+ @Entity
+ public class User extends AbstractDomainObject
+ {
+   @NotNull @Column @Size(min = 2, max = 64)
+   private String firstName;
+ 
+   @LastName @NotNull @Column @Size(min = 2, max = 64)
+   private String lastName;
+ }
+ 
+ @Target({METHOD, FIELD})
+ @Retention(RUNTIME)
+ @interface LastName {
+ }
+ 
+ @ConstraintSource(User.class)
+ public class UserDTO
+ {
+   //...
+ 
+   @ConstraintSource(User.class)
+   @TargetPropertyId(LastName.class)
+   private String surName;  //mapped to User#lastName
+ }
+ }}}
  
  ----
  

Mime
View raw message