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

Eric Norman edited comment on SLING-2803 at 3/30/13 7:56 PM:
-------------------------------------------------------------

If I recall correctly, sometimes errors occur before the post processor gets a 
chance to run.  So I would think doing validation as a pre processor would 
catch a larger universe of errors and give the developer a better chance of 
providing a meaningful error back to the user.  If you are doing validation in 
a post processor, there could have been other exceptions raised before it gets 
to that point.  However, doing a generic validation technique could be complex 
to do right since the request parameters can be expressed in many different 
ways.

In the sling projects where I have done validation, I have always registered my 
own servlet/script for the POST method that pre-validates the expected request 
parameters.  If there are any errors, I collect the info and forward back to 
the original html page to display the form again with the errors reported.  If 
there are no validation errors, I would just forward the request to the default 
sling post servlet to do the rest of the work.

Trying to do validation for the generic post servlet is a more challenging 
problem since I can imagine situations where a submitted value is valid for a 
node/resource type but not valid for a specific use case.  For example, perhaps 
in a field in a form is sending a date value that the user picks from a 
calendar.  The validator for the resource type could validate that the supplied 
value has the right syntax for a calendar value, but perhaps in some usage of 
that resource type, the calendar value must be in future.   My point is that I 
wouldn't want to have to make new resource types to modify the validation 
behavior for different contexts.


                
      was (Author: edn):
    If I recall correctly, sometimes errors occur before the post processor 
gets a chance to run.  So I would think doing validation as a pre processor 
would catch a larger universe of errors and give the developer a better chance 
of providing a meaningful error back to the user.  If you are doing validation 
in a post processor, there could have been other exceptions raised before it 
gets to that point.  However, doing a generic validation technique could be 
complex to do right since the request parameters can be expressed in many 
different ways.

In the sling projects where I have done validation, I have always registered my 
own servlet/script for the POST method that pre-validates the expected request 
parameters.  If there are any errors, I collect the info and forward back to 
the original html page to display the form again with the errors reported.  If 
there are no validation errors, I would just forward the request to the default 
sling post servlet to do the rest of the work.

Trying to do validation for the generic post servlet is a more challenging 
problem since I can imagine situations where a submitted value is valid for a 
node/resource type but not valid for a specific use case.  For example, perhaps 
in a field in a form is sending a date value that the user picks from a 
calendar.  The validator resource type could validate that the supplied value 
has the right syntax for a calendar value, but perhaps in some usage of that 
resource type, the calendar value must be in future.   My point is that I 
wouldn't want to have to make new resource types to modify the validation 
behavior for different contexts.


                  
> Create a Validation module capable of validating POST requests or Resources
> ---------------------------------------------------------------------------
>
>                 Key: SLING-2803
>                 URL: https://issues.apache.org/jira/browse/SLING-2803
>             Project: Sling
>          Issue Type: New Feature
>            Reporter: Radu Cotescu
>
> Several Sling users have asked in the past [1] about a Validation mechanism 
> in Sling that's able to validate data coming from the user. However, such a 
> module is still missing.
> This issue is meant to track the work progress on such a module.
> Ideally the module should be able to validate both request parameters and 
> Resources, by obtaining their properties via a ValueMap and provide feedback 
> in case of a validation error.
> [1] - http://sling.markmail.org/search/?q=validation

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to