1. JSF in der Praxis
28.11.2010 1DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator
2. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 2
MyFaces Extensions-Validator
What’s new in version 4
3. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 3
Agenda
• Mapped Constraint Sources
• Performance Improvements
• New and Improved Constraints
• Type-safe Config (Java-Config)
• Support for @Valid
• Interoperability
• Misc
4. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 4
Mapped Constraint Sources - 1
• The problem
• Multiple classes might contain the same
properties (e.g. DTOs, PageBeans,…)
• Some architectures don’t allow e.g. to share
the domain model across layers
• That violates the DRY principle for constraints
• The solution
• Annotations for referencing the source of a
constraint
• Works for ExtVal as well as BV constraints
5. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 5
Mapped Constraint Sources - 2
• Simple Example
@ConstraintSource(User.class)
public class UserDTO
{
//mapped automatically to User#firstName
private String firstName;
//mapped automatically to User#lastName
private String lastName;
//...
}
6. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 6
Mapped Constraint Sources - 2
• Further annotations for properties
• @ConstraintSource
• @TargetProperty
• @TargetPropertyId
• @IgnoreConstraintSource
• These annotations allow to
• map to a property with a different name
(same source)
• map to a different constraint source
• ignore the constraint source for a property
7. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 7
Performance Improvements
8. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 8
New and Improved Constraints
• New Constraints
• @EmptyIf
• Improved
• @Equals and @NotEquals
• Configurable message-target
(#validationErrorMsgTarget)
• Optional case-insensitive text comparisons
(via Constraint-Parameter: CaseInsensitive)
9. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 9
@EmptyIf Constraint - 1
• Example 1
public class MyBean
{
private String property1;
//has to be empty if property1 is not empty
@EmptyIf(valueOf = "property1")
private String property2;
//...
}
10. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 10
@EmptyIf Constraint - 2
• Example 2
public class MyBean
{
private String property1;
//has to be empty if property1 is empty
@EmptyIf(valueOf = "property1", is = empty)
private String property2;
//...
}
11. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 11
Type-safe Config - 1
• Instead of conversations or configuration
via web.xml ExtVal now allows to use a
simple Java-API within Startup-Listeners
12. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 12
Type-safe Config - 2
• Example
Extend the default or abstract
implementations of a config
(e.g. ExtValCoreConfiguration)
and register it via:
ExtValCoreConfiguration.use(
customExtValCoreConfiguration, true);
13. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 13
Support for @Valid (BV Module) - 1
• MyFaces ExtVal allows validation of
constraints within custom types via the
@Valid BV-Annotation
14. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 14
Support for @Valid (BV Module) - 2
• Example
public class CustomType {
@NotNull
private String property1;
@Size(min = 3)
private String property2;
//...
}
public class MyBean {
@NotNull
@Valid
private CustomType property;
//...
}
Constraints within
a cusotm type.
15. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 15
Interoperability
• MyFaces CODI
• CDI based dependency injection for
constraints validators will be done by CODI if
both libs are used.
• MyFaces Ext-Script
16. 28.11.2010 DI (FH) Gerhard Petracek / MyFaces-Extensions-Validator 16
Misc
• Improved JSF 2.0 support
• Bugfixing based on Community Feedback
• Moved to JUL (from Commons-Logging)
• Improved JavaDoc and JUnit Tests
• Started to move the documentation to
http://cwiki.apache.org/confluence/display/EXTVAL/
• Add-ons
• Multi-Field-Validation for BV (new)
• Required Label (new)
• Existing Add-ons will continue at Bitbucket