grailsgrails-domain-classgrails-controllergrails-validationgrails-constraints

Grails: Property Null error


I've a domain called Modulo with some properties and a Controller with a method that create a object from model and save it, when execute save the shell show this error:

But if i set the constraint nullable to true, the error show again. I think that i should not set this cosntraint.

The model is linked to a mysql table with all properties except id allow null.

I think I am not doing something wrong here. Any advice??

Domain: Modulo

class Modulo {
    String nombre
    String icon
    String url




//static constraint = {
  //    url(nullable:true)
  //}

  }

Controller: Example

class ExampleController {
    def index = { 
       def modulo = new Modulo(
         nombre:'xxx',
         icon:'xxx'
        )

        if (modulo.save()){
          println 'ok'
        }else{
          modulo.errors.allErrors.each { println it.defaultMessage}
        }
    }
}

Thanks. José


Solution

  • Finally I resolved the error. That doesn't save because constrain was write wrong.

    Error Code

     static constraint = {
         url(nullable:true)
     }
    

    Good Code

    static constraints = {
         url(nullable:true)
     }
    

    Thanks all for yours answers. :P