checkboxbooleangrails-2.2

Binding Boolean value for checkbox in Grails 2.2.4


Currently we are upgrading Grails version from 1.3.3 to 2.2.4. While doing so, we encountered a Boolean binding problem for a check-box value.

Here is the code...

Domoan: 
    A {
         :
         :
         Boolean check
      }
View: 
              :
              :
          <g:checkbox name = "check" value = &{A?.Check}/>

Controller:
   def Save {
           def aInstance = new A(params)
           if (aInstance.check)
           }  

In the above case the Boolean values are not binding properly and we are always getting "null" in the if statement.

Any idea how we could overcome this issue?

Thanks for your time.


Solution

  • After Many net surfing I got the point. Acctualay it was problem of transient value bind problem.

    Now Statically typed instance properties are bindable by default. Properties which are not bindable by default are those related to transient fields, dynamically typed properties and static properties.

    so solution is:

    The bindable constraint must be assigned a literal boolean value. Dynamic expressions are not valid values for the bindable constraint. The value must be the literal true or false.

    In my issue:

    Domoan:

    A {
         :
         :
         Boolean check
         static transients = ['check']
         static constraints = {
           check bindable: true
           :
           : 
         }
    

    }

    source: http://grails.org/doc/latest/ref/Constraints/bindable.html