You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2015/07/29 09:39:42 UTC

svn commit: r1693196 - /sling/site/trunk/content/documentation/bundles/validation.mdtext

Author: kwin
Date: Wed Jul 29 07:39:42 2015
New Revision: 1693196

URL: http://svn.apache.org/r1693196
Log:
SLING-4876 document inheritance of validation models

Modified:
    sling/site/trunk/content/documentation/bundles/validation.mdtext

Modified: sling/site/trunk/content/documentation/bundles/validation.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/bundles/validation.mdtext?rev=1693196&r1=1693195&r2=1693196&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/bundles/validation.mdtext (original)
+++ sling/site/trunk/content/documentation/bundles/validation.mdtext Wed Jul 29 07:39:42 2015
@@ -13,7 +13,7 @@ To validate a resource one first needs t
 
     ::java
     try {
-        ValidationModel validationModel = validationService.getValidationModel(resource);
+        ValidationModel validationModel = validationService.getValidationModel(resource, true);
         if (validationModel != null) {
       	    ValidationResult result = validationService.validate(resource, validationModel);
       	    if (!result.isValid()) {
@@ -37,7 +37,7 @@ Apart from that it is also possible to v
                 return true;
             }
     	}
-      	ValidationResult result = validationService.validateResourceRecursively(resource, false, ignoreResourceType1Predicate);
+      	ValidationResult result = validationService.validateResourceRecursively(resource, false, ignoreResourceType1Predicate, false);
       	if (!result.isValid()) {
         	// give out validation messages from result.getFailureMessages()
       	}
@@ -48,6 +48,8 @@ Apart from that it is also possible to v
         // one of the resource types is absolute or there was no validation model found for at least one sub resource
     }
     
+All methods to retrieve a validation model support a boolean parameter `considerResourceSuperTypeModels`. If this is set to true, the validation model is not only being looked up for exactly the given resource type but also for all its resource super types. The returned model is then a merged model of all found validation model along the resource type hierarchy.
+    
 # Validation Model Resources
 The `ValidationModel` is constructed from resources with the resourceType **sling/validation/model**. Those resources are considered validation model resources if they are located
 
@@ -56,7 +58,7 @@ The `ValidationModel` is constructed fro
  
 The resources should have the following format:
 
-  Property/Node Name      | Property or Resource |  Type   |  Description   |  Mandatory   |  Example 
+  Property/Resource Name      | Property or Resource |  Type   |  Description   |  Mandatory   |  Example 
 -------------------- | ------- | -------------- | -------------| ---------
 `sling:resourceType` | Property | `String` | Always `sling/validation/model`, otherwise node will never be picked up by Sling Validation. | yes | `sling/validation/model`
 `validatedResourceType` | Property | `String` | The resource type of the resource for which this validation model should be applied. Must always be relative (i.e. not start with a "/"). | yes | `my/own/resourcetype` 
@@ -72,6 +74,8 @@ The resources should have the following
 `children\<resourceName>\optional` | Property | `Boolean` | If `true` it is not an error if there is no resource with the given `<resourceName>` or none matching the  `nameRegex`. If not set or `false` the resource must be there.  | no | `false`
 `children\<resourceName>\properties` | Resource | - | The properties can be configured on the child level in the same way as on the root level. | no | -
 
+## Overwriting Properties or Children in Super Models
+Sling Validation optionally supports the inheritance of Sling Validation Models. To overwrite some property or child from one of the super type models, just define a property/child on the same level and with the same name in a model for a resource type which is more specific! That way the property/child on the super validation model is no longer effective.
 
 # Usage in [Sling Models]({{ refs.models.path }})
 ## Since Sling Models 1.2.0