JSF in der Praxis
24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   1
MyFaces Extensions-Validator
             What’s new in version 3




24.03.2010     DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   2
Agenda - 1
• Bean-Validation Integration Module
     (JSR 303 for JSF 1.x & 2.x + special Features)
• Improved Support for
  3rd Party Component Libraries
• Typesafe Constraint Parameters
• Constraint Severity
• Pluggable Storages
• Meta-Data Filters
• Validation Interception
24.03.2010       DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   3
Agenda - 2
• SkipValidationEvaluator
• Optional Invocation Order
• Integration of RAD-Add-on
• Additional Static Syntax for
  @JoinValidation
• Empty-/Null-Value Markers
• Other Improvements
• New Add-ons

24.03.2010   DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   4
Bean-Validation Integration
• JSR 303 for JSF 1.x and JSF 2.x
• Integration Module as alternative/addition
  to the Property-Validation Module
• Compatible with all BV conform
  implementations
• Module provides additional features
• Advantage: It’s the (new) standard
• Disadvantage: Not all features of ExtVal
  will be available (due to spec. restrictions)
24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   5
ExtVal vs. JSF 2 BV-Integration
• With ExtVal
     • @NotNull validation enabled by default
       (deactivation via std. JSF config)
     • Typesafe group validation
             • No Validation Markup in the Page
             • The ExtValBeanValidationContext allows
               custom implementations e.g. tags, configs,…
     • Component initialization
       (e.g. @NotNull    client-side required)
     • Severity aware validation


24.03.2010             DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   6
ExtVal vs. JSF 2 BV-Integration
     • Model based validation
     • Sorted violation messages
     • Out-of-the-box dependency injection support
       for constraint-validators




24.03.2010       DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   7
ExtVal Annotations for BV
• @BeanValidation
  for Group-Validation
• @ModelValidation
  class level validation of an explicit or
  implicit target




24.03.2010     DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   8
@BeanValidation
• Normally used in Page-Beans
• Available attributes
     •       viewIds (default: * for all pages)
     •       useGroups (default: Default.class)
     •       restrictGroups (default: -)
     •       conditions (default: #{true})
     •       modelValidation (default: -)
     •       List
             (equivalent to multi-constraint syntax of JSR 303)


24.03.2010                DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   9
@BeanValidation - Examples
• Simple group validation
    @BeanValidation(useGroups=Admin.class)
• Group validation for a specific view
    @BeanValidation(viewIds="/login.xhtml",
      useGroups=Admin.class)
• If group validation is defined for the whole
  bean, it might be required to exclude
  groups for special properties and/or views
    @BeanValidation(restrictGroups=Admin.class)
• Conditional group validation
    @BeanValidation(useGroups = Admin.class,
      conditions="#{user.role.privileged}")
24.03.2010     DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   10
@ModelValidation
• To trigger bean-validation after
  „Update model values" phase
• Also uses information of @BeanValidation
• Difference:
  @ModelValidation isn‘t accumulated
• Available attributes
     •       isActive (default: false)
     •       displayInline (default: false)
     •       validationTargets (default: current base object)
     •       message (default: -)
24.03.2010              DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   11
3rd Party Component Libraries
• Improved support for
     • Trinidad
     • ICEfaces
     • RichFaces
• New sandbox project e.g. for external
  component support modules to improve
  compatibility with 3rd party component
  libraries
  (http://code.google.com/p/sandbox890)


24.03.2010         DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   12
Typesafe Constraint Parameters
• Similar to the payload-attribute of BV
  (Payload is the subset of Constraint
  Parameters of ExtVal)
• Allows typesafe and reusable parameters
• Simple example - alternative for:
    @MyConstraint(payload = "warn")
    With Bean-Validation:
    @MyConstraint(payload = Warn.class)
• Processed by Add-ons or Component
  Libraries
24.03.2010         DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   13
Constraint Severity
• Constraints with Severity Info and Warn
  don‘t "stop" the JSF-Lifecycle
• ExtVal 1.x.3 provides out-of-the-box
     •       ViolationSeverity.Info.class
     •       ViolationSeverity.Warn.class
     •       ViolationSeverity.Error.class (= default)
     •       ViolationSeverity.Fatal.class




24.03.2010              DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   14
Optional: Pluggable Parameters
• ExtVal allows to map custom classes to the
  default implementations (esp. to avoid
  dependencies of BV Constraints to ExtVal)
• Mapping via
     • Global-ExtVal-Parameter
     • Static config
• Examples are available in the ExtVal Wiki



24.03.2010      DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   15
Pluggable Storages
• Generic mechanism which provides scoped
  storages with custom APIs
• Allows to create multiple storages of the
  same type with different names
• Allows to create different storage types
• StorageManager (per storage type)
     • Responsible for scoping
     • Allows to create and reset (custom) storages
       via an API (independent of the storage type)
• Allows to provide custom (tweaked) storage
  implementations easily
24.03.2010       DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   16
Meta-Data Filters
• Filters meta-data before it gets added to the
  meta-data storage
• Only for static meta-data manipulation
• Meta-data extraction interceptors are only
  for dynamic meta-data manipulation




24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   17
Validation Interception - 1
• Invocation:
     • Global interceptors:
       before and after the validation of a property
     • Local interceptors:
       before and after the validation of a constraint
• Allows to bypass validation of a
     • Property
     • Constraint



24.03.2010          DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   18
Validation Interception - Example
• Implementation
    public class CustomInterceptor
      implements PropertyValidationInterceptor {

             public boolean beforeValidation(
               FacesContext fC, UIComponent c,
               Object convertedObject, Map<String, Object> p) {

                 //...
                 return true;
             }

             public void afterValidation(
               FacesContext fC, UIComponent c,
               Object convertedObject, Map<String, Object> p) {

                 //...
             }
    }

24.03.2010               DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   19
Validation Interception - Example
• Usage
     • Global interceptors
             ExtValContext.getContext()
               .addPropertyValidationInterceptor(
                 new CustomInterceptor());
     • Local interceptors
             @Required(parameters = CustomInterceptor.class)
             private String name;




24.03.2010              DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   20
SkipValidationEvaluator
• Evaluates if the validation process for the
  current property should be skipped
• Allows to provide a custom evaluator




24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   21
Optional Invocation Order
• Classes which implement an interface
  which is annotated with
  @InvocationOrderSupport
  are allowed to use
  @InvocationOrder
• The annotation allows to register artifacts
  which get called e.g. before internal
  artifacts
• Default order: 1000


24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   22
Integration of RAD-Add-on
• It‘s possible to use input components
  without value-bindings.
• Use-Case:
  During prototyping sometimes developers
  have to create dummy pages without
  functionality.




24.03.2010   DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   23
Static Syntax for @JoinValidation
• In addition to the existing notations it‘s
  possible to refer a target property via
  the fully qualified class name
  + the property name
• Example:
    @JoinValidation("at.irian.demo.domain.Person:password")




24.03.2010         DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   24
Empty-/Null-Value Markers
• Marker for validation strategies instead of
  actively ignoring empty/null values
• Via Annotations
     • @EmptyValueAwareValidationStrategy
     • @NullValueAwareValidationStrategy




24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   25
Other Improvements
• Structural improvements
• Performance improvements
• (JSF-) ProjectStage support




24.03.2010   DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   26
New Add-ons - 1
• Add-ons compatible with Property- and
  Bean-Validation module
      • Transactional model validation (light)
      • Continue with warnings
• Add-ons compatible with Property-
  Validation module
      • Advanced meta-data
      • Java based config
        (Syntax inspired by Google Guice)

24.03.2010        DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   27
New Add-ons - 2
• Bean-Validation module
      • Spring managed constraint validation
        (us dependency injection in custom constraint
        validator implementations)




24.03.2010        DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   28
Links
• http://svn.apache.org/repos/asf/myfaces/extensi
  ons/validator
• http://issues.apache.org/jira/browse/EXTVAL
• http://wiki.apache.org/myfaces/Extensions/Valid
  ator/Versions/Versions/UpgradeGuide
• http://os890.blogspot.com
• http://code.google.com/p/os890/source/browse/tr
  unk/java/web/jsf/extval
• http://people.apache.org/~gpetracek/myfaces/ex
  tval

24.03.2010    DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator   29

MyFaces Extensions Validator r3 News

  • 1.
    JSF in derPraxis 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 1
  • 2.
    MyFaces Extensions-Validator What’s new in version 3 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 2
  • 3.
    Agenda - 1 •Bean-Validation Integration Module (JSR 303 for JSF 1.x & 2.x + special Features) • Improved Support for 3rd Party Component Libraries • Typesafe Constraint Parameters • Constraint Severity • Pluggable Storages • Meta-Data Filters • Validation Interception 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 3
  • 4.
    Agenda - 2 •SkipValidationEvaluator • Optional Invocation Order • Integration of RAD-Add-on • Additional Static Syntax for @JoinValidation • Empty-/Null-Value Markers • Other Improvements • New Add-ons 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 4
  • 5.
    Bean-Validation Integration • JSR303 for JSF 1.x and JSF 2.x • Integration Module as alternative/addition to the Property-Validation Module • Compatible with all BV conform implementations • Module provides additional features • Advantage: It’s the (new) standard • Disadvantage: Not all features of ExtVal will be available (due to spec. restrictions) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 5
  • 6.
    ExtVal vs. JSF2 BV-Integration • With ExtVal • @NotNull validation enabled by default (deactivation via std. JSF config) • Typesafe group validation • No Validation Markup in the Page • The ExtValBeanValidationContext allows custom implementations e.g. tags, configs,… • Component initialization (e.g. @NotNull client-side required) • Severity aware validation 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 6
  • 7.
    ExtVal vs. JSF2 BV-Integration • Model based validation • Sorted violation messages • Out-of-the-box dependency injection support for constraint-validators 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 7
  • 8.
    ExtVal Annotations forBV • @BeanValidation for Group-Validation • @ModelValidation class level validation of an explicit or implicit target 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 8
  • 9.
    @BeanValidation • Normally usedin Page-Beans • Available attributes • viewIds (default: * for all pages) • useGroups (default: Default.class) • restrictGroups (default: -) • conditions (default: #{true}) • modelValidation (default: -) • List (equivalent to multi-constraint syntax of JSR 303) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 9
  • 10.
    @BeanValidation - Examples •Simple group validation @BeanValidation(useGroups=Admin.class) • Group validation for a specific view @BeanValidation(viewIds="/login.xhtml", useGroups=Admin.class) • If group validation is defined for the whole bean, it might be required to exclude groups for special properties and/or views @BeanValidation(restrictGroups=Admin.class) • Conditional group validation @BeanValidation(useGroups = Admin.class, conditions="#{user.role.privileged}") 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 10
  • 11.
    @ModelValidation • To triggerbean-validation after „Update model values" phase • Also uses information of @BeanValidation • Difference: @ModelValidation isn‘t accumulated • Available attributes • isActive (default: false) • displayInline (default: false) • validationTargets (default: current base object) • message (default: -) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 11
  • 12.
    3rd Party ComponentLibraries • Improved support for • Trinidad • ICEfaces • RichFaces • New sandbox project e.g. for external component support modules to improve compatibility with 3rd party component libraries (http://code.google.com/p/sandbox890) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 12
  • 13.
    Typesafe Constraint Parameters •Similar to the payload-attribute of BV (Payload is the subset of Constraint Parameters of ExtVal) • Allows typesafe and reusable parameters • Simple example - alternative for: @MyConstraint(payload = "warn") With Bean-Validation: @MyConstraint(payload = Warn.class) • Processed by Add-ons or Component Libraries 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 13
  • 14.
    Constraint Severity • Constraintswith Severity Info and Warn don‘t "stop" the JSF-Lifecycle • ExtVal 1.x.3 provides out-of-the-box • ViolationSeverity.Info.class • ViolationSeverity.Warn.class • ViolationSeverity.Error.class (= default) • ViolationSeverity.Fatal.class 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 14
  • 15.
    Optional: Pluggable Parameters •ExtVal allows to map custom classes to the default implementations (esp. to avoid dependencies of BV Constraints to ExtVal) • Mapping via • Global-ExtVal-Parameter • Static config • Examples are available in the ExtVal Wiki 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 15
  • 16.
    Pluggable Storages • Genericmechanism which provides scoped storages with custom APIs • Allows to create multiple storages of the same type with different names • Allows to create different storage types • StorageManager (per storage type) • Responsible for scoping • Allows to create and reset (custom) storages via an API (independent of the storage type) • Allows to provide custom (tweaked) storage implementations easily 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 16
  • 17.
    Meta-Data Filters • Filtersmeta-data before it gets added to the meta-data storage • Only for static meta-data manipulation • Meta-data extraction interceptors are only for dynamic meta-data manipulation 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 17
  • 18.
    Validation Interception -1 • Invocation: • Global interceptors: before and after the validation of a property • Local interceptors: before and after the validation of a constraint • Allows to bypass validation of a • Property • Constraint 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 18
  • 19.
    Validation Interception -Example • Implementation public class CustomInterceptor implements PropertyValidationInterceptor { public boolean beforeValidation( FacesContext fC, UIComponent c, Object convertedObject, Map<String, Object> p) { //... return true; } public void afterValidation( FacesContext fC, UIComponent c, Object convertedObject, Map<String, Object> p) { //... } } 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 19
  • 20.
    Validation Interception -Example • Usage • Global interceptors ExtValContext.getContext() .addPropertyValidationInterceptor( new CustomInterceptor()); • Local interceptors @Required(parameters = CustomInterceptor.class) private String name; 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 20
  • 21.
    SkipValidationEvaluator • Evaluates ifthe validation process for the current property should be skipped • Allows to provide a custom evaluator 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 21
  • 22.
    Optional Invocation Order •Classes which implement an interface which is annotated with @InvocationOrderSupport are allowed to use @InvocationOrder • The annotation allows to register artifacts which get called e.g. before internal artifacts • Default order: 1000 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 22
  • 23.
    Integration of RAD-Add-on •It‘s possible to use input components without value-bindings. • Use-Case: During prototyping sometimes developers have to create dummy pages without functionality. 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 23
  • 24.
    Static Syntax for@JoinValidation • In addition to the existing notations it‘s possible to refer a target property via the fully qualified class name + the property name • Example: @JoinValidation("at.irian.demo.domain.Person:password") 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 24
  • 25.
    Empty-/Null-Value Markers • Markerfor validation strategies instead of actively ignoring empty/null values • Via Annotations • @EmptyValueAwareValidationStrategy • @NullValueAwareValidationStrategy 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 25
  • 26.
    Other Improvements • Structuralimprovements • Performance improvements • (JSF-) ProjectStage support 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 26
  • 27.
    New Add-ons -1 • Add-ons compatible with Property- and Bean-Validation module • Transactional model validation (light) • Continue with warnings • Add-ons compatible with Property- Validation module • Advanced meta-data • Java based config (Syntax inspired by Google Guice) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 27
  • 28.
    New Add-ons -2 • Bean-Validation module • Spring managed constraint validation (us dependency injection in custom constraint validator implementations) 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 28
  • 29.
    Links • http://svn.apache.org/repos/asf/myfaces/extensi ons/validator • http://issues.apache.org/jira/browse/EXTVAL • http://wiki.apache.org/myfaces/Extensions/Valid ator/Versions/Versions/UpgradeGuide • http://os890.blogspot.com • http://code.google.com/p/os890/source/browse/tr unk/java/web/jsf/extval • http://people.apache.org/~gpetracek/myfaces/ex tval 24.03.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 29