the correct way to specify Constraints

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

the correct way to specify Constraints

José Vilmar Estácio de Souza

According to https://docs.grails.org/latest/ref/Constraints/Usage.html,, we can especify constraints using the following construction:


login size: 5..15, blank: false, unique: true.

However, if a anottate the class in which this constraint is applied with '@groovy.transform.CompileStatic', I receive the following compile error:

 - Cannot find matching method demomt.Plan#login(java.util.LinkedHashMap <java.l
ang.String, java.lang.Object>). Please check if the declared type is right and i
f the method exists.

To fix the problem I need to change the declaration of the constraint to the following:

login: [ size: 5..15, blank: false, unique: true ]

I don't know if the documentation is wrong, if there is some problem with the compiler or if I am doing something wrong.

Thanks.



--
Assinatura Informal José Vilmar, Telefones: 21 2555-2650 e 21 98868-0859,
        Skype: jvilmar

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/9acd69c2-782c-7fe9-2569-5291709b399b%40informal.com.br.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: the correct way to specify Constraints

Jeff Scott Brown-4
On 5 Oct 2017, at 15:21, José Vilmar Estácio de Souza wrote:

> According to
> https://docs.grails.org/latest/ref/Constraints/Usage.html,, we can
> especify constraints using the following construction:
>
>
> |login size: 5..15, blank: false, unique: true. However, if a anottate
> the class in which this constraint is applied with
> '@groovy.transform.CompileStatic', I receive the following compile
> error: - Cannot find matching method
> demomt.Plan#login(java.util.LinkedHashMap <java.l ang.String,
> java.lang.Object>). Please check if the declared type is right and i f
> the method exists. To fix the problem I need to change the declaration
> of the constraint to the following: login: [ size: 5..15, blank:
> false, unique: true ] I don't know if the documentation is wrong, if
> there is some problem with the compiler or if I am doing something
> wrong. Thanks. |
>
>

The way you have defined the constraints is fine.  The problem is that
the static type checker won’t let you to call login(Map) (that is not
a bug, that is by design).  Instead of using CompileStatic, use
GrailsCompileStatic.  The difference between them is GrailsCompileStatic
attaches some type checking extensions which are aware of certain Grails
idioms like dynamic dispatch in a constraints block.




JSB

--
Jeff Scott Brown
OCI Grails Practice Lead
Principal Software Engineer

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/D45E3823-B20F-42E8-A38F-2BED25C970BA%40objectcomputing.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: the correct way to specify Constraints

José Vilmar Estácio de Souza

Thanks Jeff. Working perfectly.


On 10/06/2017 07:09 AM, Jeff Scott Brown wrote:
On 5 Oct 2017, at 15:21, José Vilmar Estácio de Souza wrote:

According to https://docs.grails.org/latest/ref/Constraints/Usage.html,, we can especify constraints using the following construction:


|login size: 5..15, blank: false, unique: true. However, if a anottate the class in which this constraint is applied with '@groovy.transform.CompileStatic', I receive the following compile error: - Cannot find matching method demomt.Plan#login(java.util.LinkedHashMap <java.l ang.String, java.lang.Object>). Please check if the declared type is right and i f the method exists. To fix the problem I need to change the declaration of the constraint to the following: login: [ size: 5..15, blank: false, unique: true ] I don't know if the documentation is wrong, if there is some problem with the compiler or if I am doing something wrong. Thanks. |



The way you have defined the constraints is fine.  The problem is that the static type checker won’t let you to call login(Map) (that is not a bug, that is by design).  Instead of using CompileStatic, use GrailsCompileStatic.  The difference between them is GrailsCompileStatic attaches some type checking extensions which are aware of certain Grails idioms like dynamic dispatch in a constraints block.




JSB

--
Jeff Scott Brown
OCI Grails Practice Lead
Principal Software Engineer

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


--
Assinatura Informal José Vilmar, Telefones: 21 2555-2650 e 21 98868-0859,
        Skype: jvilmar

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/d07361c3-503f-931a-a95f-63231e1ff083%40informal.com.br.
For more options, visit https://groups.google.com/d/optout.