(Quick Reference)

bindable

Purpose

Configure the bindability of a property.

Examples

salary bindable: false
firstName size: 5..15, bindable: true
department bindable: true

Description

Set to false to indicate that a property is not to be automatically assigned a value during data binding.

package com.demo

class Employee {
    String firstName
    String department
    BigDecimal salary

    static constraints = {
        department bindable: false
        salary bindable: false
    }
}
import com.demo.Employee

def employee = new Employee()
employee.firstName = 'Bill'
employee.department = 'Percussion'
employee.salary = 42.0

// department and salary will NOT be bound because they are configured as non-bindable in the Employee.constraints closure
employee.properties = [firstName: 'William',
                       department: 'Retired',
                       salary: 99.99]

assert 'William' == employee.firstName
assert 'Percussion' == employee.department
assert 42.0 == employee.salary

Properties without explicit bindable constraints are eligible for mass data binding by default for compatibility. Statically typed instance properties are bindable unless they are marked with bindable: false, are transient fields, are dynamically typed properties, or are static properties.

Applications can opt into deny-by-default binding allowlists by setting grails.databinding.denyByDefault=true. In secure mode, only properties declared with bindable: true, supplied in an explicit include list to bindData, or named by @BindAllowed on a controller action command object parameter are bound. Properties marked bindable: false remain non-bindable in either mode.

See the data binding section for more details on data binding.

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.

The bindable constraint must be applied in the constraints closure which is defined in the relevant class. This means that bindable may not be used as a shared constraint.