Grails validateable not work for non-persistent domain class

前端 未结 2 1932
独厮守ぢ
独厮守ぢ 2021-01-25 18:53

I followed the instruction here: http://www.grails.org/doc/latest/guide/7.%20Validation.html

and added into config.groovy:

grails.valida         


        
相关标签:
2条回答
  • 2021-01-25 19:29

    You really need to call validate() before - it will trigger validation and change object state. Looking at ValidationGrailsPlugin.addValidationMethods(), I see that hasErrors() is a read-only method.

    Your sample worked for me after calling validate(). I tried in grails console (great tool, I highly recommend it!):

    Warm w = new Warm('')
    w.hasErrors() // 'Result: false'
    w.validate()
    w.hasErrors() // 'Result: true'
    

    I added @Validateable to Warm class. I believe it makes no difference.

    0 讨论(0)
  • 2021-01-25 19:29

    I don't think the validate() and hasErrors() dynamic methods are added in a Unit test. If you move this to an integration test they should be there.

    0 讨论(0)
提交回复
热议问题