List of scanned objects

Hi, I am trying to check an object with a list of objects inside it. The root instance comes from the JSON client file.

I created something like this

@Validateable
class Book {
    String title
    List authors
    static hasMany = [authors : Authors]

    static constraints = {
        authors(nullable:false,validator: { recipients ->
            recipients.every { it.validate() }
        } )     
    }
}

@Validateable
class Author {
    String name
    Integer property

        static constraints = {
        name(nullable:false)    
        property((nullable:false, blank: false))    
    }
}

And I try to check it in the controller as follows:

class BookController {

def manageBook(Book book){
    if (book.validate()) {
        //Do my stuff
    }else{
        // return error
    }
}
}

But it doesn’t work at all, and I see this error in the console:

| Error 2012-05-25 11:26:34,014 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [POST] /BookApp/rest/bookApp/manageBook
No signature of method: org.codehaus.groovy.grails.web.json.JSONObject.validate() is applicable for argument types: () values: []
Possible solutions: wait(), values(). Stacktrace follows:
Message: No signature of method: org.codehaus.groovy.grails.web.json.JSONObject.validate() is applicable for argument types: () values: []
Possible solutions: wait(), values()
   Line | Method
->>  17 | doCall  in dataskaterserver.DeviceSeenWifiData$__clinit__closure1_closure2_closure3
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run . . in     ''
^   680 | run     in java.lang.Thread

Can someone help me please.?

+3
source share
1 answer

I found a solution, it was in the documentation ... http://grails.org/doc/latest/guide/validation.html#validationNonDomainAndCommandObjectClasses

Validateable, . , , - ( ), , grails.validateable.classes Config.groovy @:

grails.validateable.classes = [com.mycompany.myapp.User, com.mycompany.dto.Account]
+1

All Articles