You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Katarzyna Kozlowska <ka...@cognifide.com> on 2014/05/18 00:08:14 UTC

Silng Models Validation Framework

Hello list,

I was thinking about contributing to Sling and creating Sling Models
Validation Framework. I was inspired by JSR 303 and I want to base my
solution on annotations. I would really appreciate your feedback on my
idea.

Best Regards,
Kasia

Re: Silng Models Validation Framework

Posted by Katarzyna Kozlowska <ka...@cognifide.com>.
Hi Justin,

yes you are probably right. However there are few downsides of this
approach I can think of:
- i'm not sure if it is worth to add such a big library to a project if you
want to use just a small part
- there is no fun :)

But I will verify that. Maybe this solution will work for me. And then I
will think of something else I can write myself.

Kind Regards,
Kasia



On Thu, May 22, 2014 at 8:48 PM, Justin Edelson <ju...@justinedelson.com>wrote:

> Hi Kasia,
> Is it not possible to just use a JSR 303 implementation against your
> model objects? Since they are essentially just POJOs, I would expect
> this to be the case.
>
> Regards,
> Justin
>
> On Thu, May 22, 2014 at 2:40 AM, Katarzyna Kozlowska
> <ka...@cognifide.com> wrote:
> > Hi again,
> >
> > generally I like the resource base validation very much. However after
> > going through jira Radu provided I am not sure if it is proper solution
> for
> > my problem.
> > First of all I don't want to filter improper data or stop them from being
> > saved to the repository. I just want to get validation errors, if any,
> and
> > display them in the ui.
> > The second part is that when I am using Sing Models my abstraction layer
> is
> > not aware of the resource anymore and I would like to keep it that way.
> > For me the perfect solution for Sling Models would be designed in the way
> > where user must only use simple annotations like:
> >
> > @NotBlank
> > @Length(max=25, message="Title field must not be longer then 25
> characters")
> > private String title
> >
> > and there would be a validate() method returning some kind of validation
> > results map/list based on annotations
> >
> > Important part is that there should be a predefined set of annotations
> with
> > default messages, but the possibility to add some custom ones is a must.
> > Therefore right now I can see one point we could merge this to different
> > approaches and it is this common set of simple code validating separate
> > values.
> >
> > I would love to discuss this solution further.
> >
> > Kind regards,
> > Kasia
> >
> >
> >
> > On Tue, May 20, 2014 at 12:13 PM, Konrad Windszus <ko...@gmx.de>
> wrote:
> >
> >> The problem with connecting something like that with Sling Models is the
> >> way the adaptTo method was specified.
> >> It is supposed to return null and never throw an exception. So all
> >> exceptions being caused by e.g. validation errors must be caught within
> >> Sling Models. Currently I don’t see any way to propagate those
> exceptions
> >> across the adaptTo boundary. That might already be a problem when for
> >> example some required properties are missing. It is much harder to debug
> >> because the exception is caught within the Sling Models framework.
> >> I would like to have the possibility to instantiate a model class and to
> >> be able to catch all potential exceptions within my own code.
> >> Konrad
> >>
> >> On 19 May 2014, at 14:53, Bertrand Delacretaz <bd...@apache.org>
> >> wrote:
> >>
> >> > On Mon, May 19, 2014 at 1:43 PM, Radu Cotescu <ra...@cotescu.com>
> wrote:
> >> >> ...Maybe we can revive that topic and merge the two ideas....
> >> >
> >> > That would be great, IIRC Radu's SLING-2803 validator is meant to be
> >> > generic, using it within Sling models should then just be another use
> >> > case.
> >> >
> >> > -Bertrand
> >>
> >>
>

Re: Silng Models Validation Framework

Posted by Justin Edelson <ju...@justinedelson.com>.
Hi Kasia,
Is it not possible to just use a JSR 303 implementation against your
model objects? Since they are essentially just POJOs, I would expect
this to be the case.

Regards,
Justin

On Thu, May 22, 2014 at 2:40 AM, Katarzyna Kozlowska
<ka...@cognifide.com> wrote:
> Hi again,
>
> generally I like the resource base validation very much. However after
> going through jira Radu provided I am not sure if it is proper solution for
> my problem.
> First of all I don't want to filter improper data or stop them from being
> saved to the repository. I just want to get validation errors, if any, and
> display them in the ui.
> The second part is that when I am using Sing Models my abstraction layer is
> not aware of the resource anymore and I would like to keep it that way.
> For me the perfect solution for Sling Models would be designed in the way
> where user must only use simple annotations like:
>
> @NotBlank
> @Length(max=25, message="Title field must not be longer then 25 characters")
> private String title
>
> and there would be a validate() method returning some kind of validation
> results map/list based on annotations
>
> Important part is that there should be a predefined set of annotations with
> default messages, but the possibility to add some custom ones is a must.
> Therefore right now I can see one point we could merge this to different
> approaches and it is this common set of simple code validating separate
> values.
>
> I would love to discuss this solution further.
>
> Kind regards,
> Kasia
>
>
>
> On Tue, May 20, 2014 at 12:13 PM, Konrad Windszus <ko...@gmx.de> wrote:
>
>> The problem with connecting something like that with Sling Models is the
>> way the adaptTo method was specified.
>> It is supposed to return null and never throw an exception. So all
>> exceptions being caused by e.g. validation errors must be caught within
>> Sling Models. Currently I don’t see any way to propagate those exceptions
>> across the adaptTo boundary. That might already be a problem when for
>> example some required properties are missing. It is much harder to debug
>> because the exception is caught within the Sling Models framework.
>> I would like to have the possibility to instantiate a model class and to
>> be able to catch all potential exceptions within my own code.
>> Konrad
>>
>> On 19 May 2014, at 14:53, Bertrand Delacretaz <bd...@apache.org>
>> wrote:
>>
>> > On Mon, May 19, 2014 at 1:43 PM, Radu Cotescu <ra...@cotescu.com> wrote:
>> >> ...Maybe we can revive that topic and merge the two ideas....
>> >
>> > That would be great, IIRC Radu's SLING-2803 validator is meant to be
>> > generic, using it within Sling models should then just be another use
>> > case.
>> >
>> > -Bertrand
>>
>>

Re: Silng Models Validation Framework

Posted by Katarzyna Kozlowska <ka...@cognifide.com>.
Hi again,

generally I like the resource base validation very much. However after
going through jira Radu provided I am not sure if it is proper solution for
my problem.
First of all I don't want to filter improper data or stop them from being
saved to the repository. I just want to get validation errors, if any, and
display them in the ui.
The second part is that when I am using Sing Models my abstraction layer is
not aware of the resource anymore and I would like to keep it that way.
For me the perfect solution for Sling Models would be designed in the way
where user must only use simple annotations like:

@NotBlank
@Length(max=25, message="Title field must not be longer then 25 characters")
private String title

and there would be a validate() method returning some kind of validation
results map/list based on annotations

Important part is that there should be a predefined set of annotations with
default messages, but the possibility to add some custom ones is a must.
Therefore right now I can see one point we could merge this to different
approaches and it is this common set of simple code validating separate
values.

I would love to discuss this solution further.

Kind regards,
Kasia



On Tue, May 20, 2014 at 12:13 PM, Konrad Windszus <ko...@gmx.de> wrote:

> The problem with connecting something like that with Sling Models is the
> way the adaptTo method was specified.
> It is supposed to return null and never throw an exception. So all
> exceptions being caused by e.g. validation errors must be caught within
> Sling Models. Currently I don’t see any way to propagate those exceptions
> across the adaptTo boundary. That might already be a problem when for
> example some required properties are missing. It is much harder to debug
> because the exception is caught within the Sling Models framework.
> I would like to have the possibility to instantiate a model class and to
> be able to catch all potential exceptions within my own code.
> Konrad
>
> On 19 May 2014, at 14:53, Bertrand Delacretaz <bd...@apache.org>
> wrote:
>
> > On Mon, May 19, 2014 at 1:43 PM, Radu Cotescu <ra...@cotescu.com> wrote:
> >> ...Maybe we can revive that topic and merge the two ideas....
> >
> > That would be great, IIRC Radu's SLING-2803 validator is meant to be
> > generic, using it within Sling models should then just be another use
> > case.
> >
> > -Bertrand
>
>

Re: Silng Models Validation Framework

Posted by Konrad Windszus <ko...@gmx.de>.
The problem with connecting something like that with Sling Models is the way the adaptTo method was specified. 
It is supposed to return null and never throw an exception. So all exceptions being caused by e.g. validation errors must be caught within Sling Models. Currently I don’t see any way to propagate those exceptions across the adaptTo boundary. That might already be a problem when for example some required properties are missing. It is much harder to debug because the exception is caught within the Sling Models framework.
I would like to have the possibility to instantiate a model class and to be able to catch all potential exceptions within my own code.
Konrad

On 19 May 2014, at 14:53, Bertrand Delacretaz <bd...@apache.org> wrote:

> On Mon, May 19, 2014 at 1:43 PM, Radu Cotescu <ra...@cotescu.com> wrote:
>> ...Maybe we can revive that topic and merge the two ideas....
> 
> That would be great, IIRC Radu's SLING-2803 validator is meant to be
> generic, using it within Sling models should then just be another use
> case.
> 
> -Bertrand


Re: Silng Models Validation Framework

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Mon, May 19, 2014 at 1:43 PM, Radu Cotescu <ra...@cotescu.com> wrote:
> ...Maybe we can revive that topic and merge the two ideas....

That would be great, IIRC Radu's SLING-2803 validator is meant to be
generic, using it within Sling models should then just be another use
case.

-Bertrand

Re: Silng Models Validation Framework

Posted by Radu Cotescu <ra...@cotescu.com>.
Hi Kasia,

A similar effort was started by me a while back - see SLING-2803 [0],
though I've proposed a content-based validation model.
Maybe we can revive that topic and merge the two ideas.

Cheers,
Radu

[0] - https://issues.apache.org/jira/browse/SLING-2803


On Sun, May 18, 2014 at 1:08 AM, Katarzyna Kozlowska <
katarzyna.kozlowska@cognifide.com> wrote:

> Hello list,
>
> I was thinking about contributing to Sling and creating Sling Models
> Validation Framework. I was inspired by JSR 303 and I want to base my
> solution on annotations. I would really appreciate your feedback on my
> idea.
>
> Best Regards,
> Kasia
>