You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2009/04/08 02:14:01 UTC

[Myfaces Wiki] Update of "Extensions/Validator/DevDoc" by GerhardPetracek

Dear Wiki user,

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

The following page has been changed by GerhardPetracek:
http://wiki.apache.org/myfaces/Extensions/Validator/DevDoc

------------------------------------------------------------------------------
  
  == JSR 303 integration ==
  
+ the current goal is that myfaces extval provides bean-validation (jsr 303) integration for all jsf versions (1.x and 2.x).
+ 
  '''TODO''' (the integration depends on the final version of the specification and the reference implementation)
  
+ === group validation (partial validation) ===
+ jsf 2.0 integrates bean validation via tags[[BR]]
+ e.g.: <f:validateBean validationGroups="javax.validation.groups.Default,app.validation.groups.Order"/>[[BR]]
+ first of all it's quite a lot to type the fully qualified class name within a page[[BR]]
+ myfaces-core 2 has to impl. this tag, because it's part of the spec.[[BR]]
+ 
+ myfaces extval is able to provide an alternative approach.[[BR]]
+ extval provides a generic api which looks like:
+ {{{
+ ExtValBeanValidationContext.getCurrentInstance().addGroup(...)
+ }}}
+ 
+ so it's possible to provide different approaches to define groups which have to be added to this context.[[BR]]
+ it would be possible via a tag. anyway, to reduce the complexity of pages extval provides annotations for it.
+ 
+ first of all - partial validation shouldn't be used extensively to avoid too complex pages.[[BR]]
+ the annotaton approach is similar to the view-controller annotation of orchestra.
+ 
+ the idea is to annotate page beans and/or their properties
+ 
+ the following examples are available [http://svn.apache.org/repos/asf/myfaces/extensions/validator/branches/beanval_integration/trunk/examples/hello_world/ here][[BR]]
+ they are based on the hello world application of myfaces
+ 
+ example 1:
+ {{{
+ @BeanValidationController
+ public class HelloWorldController {...}
+ }}}
+ 
+ ... that means:[[BR]]
+ the default group (javax.validation.groups.Default) is used for all pages which are using this page bean.
+ 
+ example 2:
+ {{{
+ public class HelloWorldController
+ {
+     @BeanValidationController(@Validate(viewId = "/form1.jsp"))
+     private Person person = new Person();
+ ...
+ }
+ }}}
+ 
+ ... that means:[[BR]]
+ the default group (javax.validation.groups.Default) is used just for view-id form1.jsp[[BR]]
+ (if there is also an annotation at the class (see example 1) both information get added to the context.)
+ 
+ example 3:
+ {{{
+ public class HelloWorldController
+ {
+     private Person person = new Person();
+ 
+     @BeanValidationController({
+             @Validate(viewId = "/helloWorld.jsp"),
+             @Validate(viewId = "/form1.jsp", partialValidation = {@Group(User.class)}),
+             @Validate(viewId = "/form2.jsp", partialValidation = {@Group(Admin.class)})
+             }
+     )
+     public Person getPerson()
+     {
+         return person;
+     }
+ ...
+ }
+ }}}
+ 
+ ... that means:[[BR]]
+ the default group (javax.validation.groups.Default) is used for helloWorld.jsp[[BR]]
+ the User group is used to validate form1.jsp[[BR]]
+ the Admin group is used to validate form2.jsp
+ 
+ ==== possible targets ====
+  * page bean class
+  * page bean fields/properties
+  * last base of the bound property
+  * the bound property
+ 
+ which means:[[BR]]
+ #{pageBean.pageBeanProperty.property1.property2.propertyBase.property}
+ 
+ in this example the >possible< targets are:
+  * pageBean
+  * pageBeanProperty
+  * propertyBase (in most szenarios it this target isn't suggested)
+  * property (in most szenarios it this target isn't suggested)
+ 
+ === topics to think about ===
+ 1)
+ @Validate(viewId = "/form1.jsp", partialValidation = {@Group(User.class)}, restrict = {@Group(...)})[[BR]]
+ to remove e.g. a group which was added at the class-level for a special property
+ 
+ 2)
+ add/remove groups via annotations at action methods
+ 
  = steps for a release =
  
  [wiki:/Steps_For_A_Release release steps]