the correct way to specify Constraints

19 views
Skip to first unread message

José Vilmar Estácio de Souza

unread,
Oct 5, 2017, 3:21:41 PM10/5/17
to grails-de...@googlegroups.com

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.



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

Jeff Scott Brown

unread,
Oct 6, 2017, 6:09:25 AM10/6/17
to grails-de...@googlegroups.com
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/

José Vilmar Estácio de Souza

unread,
Oct 6, 2017, 4:04:55 PM10/6/17
to grails-de...@googlegroups.com, Jeff Scott Brown

Thanks Jeff. Working perfectly.

Reply all
Reply to author
Forward
0 new messages