Re: [grails-dev] Grails & Validation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [grails-dev] Grails & Validation

Guillaume Laforge-2
On 28/10/05, Graeme Rocher <[hidden email]> wrote:
> Ok please see my proposals for validation that supports i18ln (which
> RoR doesn't incidently):
>
> http://jira.codehaus.org/browse/GRAILS-15
>
> Feedback would be great!

I've added a little comment on this JIRA ticket.
I think using builders / closures a bit more might help improve readability.

For instance, instead of:

class User {
      @Property String login
      @Property String pass
      @Property constraints = {
                     this.login.maxLength = 16
                     this.login.minLength = 5
                     this.login.nullable = false
                     this.pass.maxLength = 10
                     this.pass.nullable = false
     }
}

I think the following  closure might be easier on the eye, by avoiding
useless repetition as well as avoiding using the ugly "this." :

class User {
    @Property String login
    @Property String pass
    @Property constraints = {
        login(maxLength: 16, minLength: 5, nullable: false)
        pass(maxLength: 10, nullable: false)
    }
}

As a little enhancement as well, in the following example:

class UserController {
         @Property login = {
                def errors = this.validator {
                        notBlank(param:"login", message:"Login not specified")
                        isNull(session:"user", message:"User already
in session")
                        maxLength(param:"login", length:10)
                }
        }
}

...we can remove again remove the ugly this too I think.

Both solutions would use builders which are nice for constructing
"things". And I think validation rules or constraints can be nicely
represented with a tree-structure like builders provide.

--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: [grails-dev] Grails & Validation

graemer
I do agree builders take less code but i did like the way it seemed
you were applying the constraint against the property:

login.maxLength = 15

Which is less clear that it is associated with the property with this syntax:

login(maxLength:15)

Graeme

On 10/11/05, Guillaume Laforge <[hidden email]> wrote:

> On 28/10/05, Graeme Rocher <[hidden email]> wrote:
> > Ok please see my proposals for validation that supports i18ln (which
> > RoR doesn't incidently):
> >
> > http://jira.codehaus.org/browse/GRAILS-15
> >
> > Feedback would be great!
>
> I've added a little comment on this JIRA ticket.
> I think using builders / closures a bit more might help improve readability.
>
> For instance, instead of:
>
> class User {
>       @Property String login
>       @Property String pass
>       @Property constraints = {
>                      this.login.maxLength = 16
>                      this.login.minLength = 5
>                      this.login.nullable = false
>                      this.pass.maxLength = 10
>                      this.pass.nullable = false
>      }
> }
>
> I think the following  closure might be easier on the eye, by avoiding
> useless repetition as well as avoiding using the ugly "this." :
>
> class User {
>     @Property String login
>     @Property String pass
>     @Property constraints = {
>         login(maxLength: 16, minLength: 5, nullable: false)
>         pass(maxLength: 10, nullable: false)
>     }
> }
>
> As a little enhancement as well, in the following example:
>
> class UserController {
>          @Property login = {
>                 def errors = this.validator {
>                         notBlank(param:"login", message:"Login not specified")
>                         isNull(session:"user", message:"User already
> in session")
>                         maxLength(param:"login", length:10)
>                 }
>         }
> }
>
> ...we can remove again remove the ugly this too I think.
>
> Both solutions would use builders which are nice for constructing
> "things". And I think validation rules or constraints can be nicely
> represented with a tree-structure like builders provide.
>
> --
> Guillaume Laforge
> http://glaforge.free.fr/blog/groovy
>
Reply | Threaded
Open this post in threaded view
|

RE: [grails-dev] Grails & Validation

Dierk König
how about this:

this.login.identity {
    maxLength = 15
    trullala = true
}

cheers
Mittie

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]On Behalf
> Of Graeme Rocher
> Sent: Donnerstag, 10. November 2005 17:36
> To: [hidden email]
> Subject: Re: [grails-dev] Grails & Validation
>
>
> I do agree builders take less code but i did like the way it seemed
> you were applying the constraint against the property:
>
> login.maxLength = 15
>
> Which is less clear that it is associated with the property with
> this syntax:
>
> login(maxLength:15)
>
> Graeme
>
> On 10/11/05, Guillaume Laforge <[hidden email]> wrote:
> > On 28/10/05, Graeme Rocher <[hidden email]> wrote:
> > > Ok please see my proposals for validation that supports i18ln (which
> > > RoR doesn't incidently):
> > >
> > > http://jira.codehaus.org/browse/GRAILS-15
> > >
> > > Feedback would be great!
> >
> > I've added a little comment on this JIRA ticket.
> > I think using builders / closures a bit more might help improve
> readability.
> >
> > For instance, instead of:
> >
> > class User {
> >       @Property String login
> >       @Property String pass
> >       @Property constraints = {
> >                      this.login.maxLength = 16
> >                      this.login.minLength = 5
> >                      this.login.nullable = false
> >                      this.pass.maxLength = 10
> >                      this.pass.nullable = false
> >      }
> > }
> >
> > I think the following  closure might be easier on the eye, by avoiding
> > useless repetition as well as avoiding using the ugly "this." :
> >
> > class User {
> >     @Property String login
> >     @Property String pass
> >     @Property constraints = {
> >         login(maxLength: 16, minLength: 5, nullable: false)
> >         pass(maxLength: 10, nullable: false)
> >     }
> > }
> >
> > As a little enhancement as well, in the following example:
> >
> > class UserController {
> >          @Property login = {
> >                 def errors = this.validator {
> >                         notBlank(param:"login", message:"Login
> not specified")
> >                         isNull(session:"user", message:"User already
> > in session")
> >                         maxLength(param:"login", length:10)
> >                 }
> >         }
> > }
> >
> > ...we can remove again remove the ugly this too I think.
> >
> > Both solutions would use builders which are nice for constructing
> > "things". And I think validation rules or constraints can be nicely
> > represented with a tree-structure like builders provide.
> >
> > --
> > Guillaume Laforge
> > http://glaforge.free.fr/blog/groovy
> >
Reply | Threaded
Open this post in threaded view
|

Re: [grails-dev] Grails & Validation

Guillaume Laforge-2
On 10/11/05, Dierk Koenig <[hidden email]> wrote:
> how about this:
>
> this.login.identity {
>     maxLength = 15
>     trullala = true
> }

Which is a standard Groovy feature ;-)
Well... Graeme will decide!

--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: [grails-dev] Grails & Validation

graemer
I've gone for the builder approach for consistency sake

Graeme

On 10/11/05, Guillaume Laforge <[hidden email]> wrote:

> On 10/11/05, Dierk Koenig <[hidden email]> wrote:
> > how about this:
> >
> > this.login.identity {
> >     maxLength = 15
> >     trullala = true
> > }
>
> Which is a standard Groovy feature ;-)
> Well... Graeme will decide!
>
> --
> Guillaume Laforge
> http://glaforge.free.fr/blog/groovy
>