You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2014/11/24 18:51:13 UTC

[jira] [Comment Edited] (SLING-4161) Support Sling Validation through a new field of the Model annotation

    [ https://issues.apache.org/jira/browse/SLING-4161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14223188#comment-14223188 ] 

Konrad Windszus edited comment on SLING-4161 at 11/24/14 5:51 PM:
------------------------------------------------------------------

The attached patches allow to leverage the Sling Validation through the model annotation. The dependency to Sling Validation should be optional.
I renamed the former InvalidModelException to ModelClassException to make more clear from the name what is a validation exception and what is not.
Also the ModelAdapterFactory might now throw two more exceptions:
SlingValidationException (in case the sling validation model could not be instanciated) and InvalidResourceException (in case the resource is considered invalid by Sling Validation)


was (Author: kwin):
The attached patches allow to leverage the Sling Validation through the model annotation. The dependency to Sling Validation should be optional.
I renamed the former InvalidModelException to ModelClassException to make more clear from the name what is a validation exception and what is not.
Also the ModelAdapterFactory might now throw two more exceptions:
SlingValidationException (in case the sling validation model could not be instanciated) and InvalidModelException (in case the resource is considered invalid by Sling Validation)

> Support Sling Validation through a new field of the Model annotation
> --------------------------------------------------------------------
>
>                 Key: SLING-4161
>                 URL: https://issues.apache.org/jira/browse/SLING-4161
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: Sling Models API 1.0.0, Sling Models Implementation 1.0.0
>            Reporter: Konrad Windszus
>            Assignee: Konrad Windszus
>         Attachments: SLING-4161-api-v02.patch, SLING-4161-impl-v02.patch
>
>
> The current way of integrating Sling Validation (SLING-2803) with Sling Models is to inject the validation service and then call it within a PostConstruct method (http://www.slideshare.net/raducotescu/apache-sling-generic-validation-framework/16).
> This has the drawback that
> # the {{ValidationService}} needs to be injected
> # a PostConstruct needs to be implemented
> # the other injections need to be marked as optional (otherwise the validation is never triggered in case of e.g. missing required valuemap values)
> Instead it would be good to support this use case with just an additional field on the annotation {{Model}} which is named {{validate}}. By default this should be {{false}} (to be backwards compatible), but if it is {{true}} the Sling Validation should be called before any values are injected into the model. If validation fails the {{ModelAdapterFactory}} should never instanciate the model and rather return null (or throw a meaningful exception for SLING-3709).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)