Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails validateable not work for non-persistent domain class
    text
    copied!<p>I followed the instruction here: <a href="http://www.grails.org/doc/latest/guide/7.%20Validation.html" rel="nofollow">http://www.grails.org/doc/latest/guide/7.%20Validation.html</a></p> <p>and added into <strong>config.groovy</strong>:</p> <pre><code>grails.validateable.classes = [liningtest.Warm'] </code></pre> <p>Then added in <strong>src/groovy/Warm.groovy</strong> (it's a non-persistent domain class):</p> <pre><code>package liningtest import org.codehaus.groovy.grails.validation.Validateable class Warm { String name; int happyCite; Warm(String n, int h) { this.name = n; this.happyCite = h; } static constraints = { name(size: 1..50) happyCite(min: 100) } } </code></pre> <p>But it just doesn't work (both "blank false" &amp; "size: 0..25") for the "hasErrors" function. It always returns false, even when the name is > 25.</p> <p>Is this a Grails bug, if yes, is there any work-around?</p> <p>I'm using Grails 1.3.3</p> <p><strong>UPDATE</strong>: I have updated the simplified code. And now I know that constraint "size" can't be used with "blank", but still does not work.</p> <p>My test class in <strong>test/unit/liningtest/WarmTests.groovy</strong></p> <pre><code>package liningtest import grails.test.* class WarmTests extends GrailsUnitTestCase { protected void setUp() { super.setUp() } protected void tearDown() { super.tearDown() } void testSomething() { def w = new Warm('Hihi', 3) assert (w.happyCite == 3) assert (w.hasErrors() == true) } } </code></pre> <p>And the error I got:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;testsuite errors="1" failures="0" hostname="evolus-50b0002c" name="liningtest.WarmTests" tests="1" time="0.062" timestamp="2010-12-16T04:07:47"&gt; &lt;properties /&gt; &lt;testcase classname="liningtest.WarmTests" name="testSomething" time="0.062"&gt; &lt;error message="No signature of method: liningtest.Warm.hasErrors() is applicable for argument types: () values: [] Possible solutions: hashCode()" type="groovy.lang.MissingMethodException"&gt;groovy.lang.MissingMethodException: No signature of method: liningtest.Warm.hasErrors() is applicable for argument types: () values: [] Possible solutions: hashCode() at liningtest.WarmTests.testSomething(WarmTests.groovy:18) &lt;/error&gt; &lt;/testcase&gt; &lt;system-out&gt;&lt;![CDATA[--Output from testSomething-- ]]&gt;&lt;/system-out&gt; &lt;system-err&gt;&lt;![CDATA[--Output from testSomething-- ]]&gt;&lt;/system-err&gt; &lt;/testsuite&gt; </code></pre> <p><strong>UPDATE 2</strong>: When I don't use Unit test, but try to call <strong><em>hasErrors</em></strong> in the controller, it runs but return false value. (hasErrors return false with Warm('Hihi', 3) ). Does anyone has a clue?</p> <p><strong>UPDATE 3</strong>: I followed Victor way, and now the problem is solved if I call validate() before hasErrors(). But I still don't understand, why "grails generate-all" controllers doesn't have to call validate() before using hasErrors()?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload