"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Controllers/bindData.html" (14 Sep 2022, 61890 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

bindData

Purpose

Allows fine-grained control of binding request parameters from strings onto objects and the necessary types (data binding).

Examples

// binds request parameters to a target object
bindData(target, params)

// exclude firstName and lastName
bindData(target, params, [exclude: ['firstName', 'lastName']])

// only use parameters starting with "author." e.g. author.email
bindData(target, params, "author")
bindData(target, params, [exclude: ['firstName', 'lastName']], "author")

// using inclusive map
bindData(target, params, [include: ['firstName', 'lastName']], "author")

Description

Usage: bindData(target, params, includesExcludes*, prefix*)

Arguments:

  • target - The target object to bind to

  • params - A Map of source parameters, often the params object when used in a controller

  • includesExcludes - (Optional) A map with 'include' and/or 'exclude' lists containing the names of properties to either include or exclude.

  • prefix - (Optional) A string representing a prefix to use to filter parameters. The method will automatically append a '.' when matching the prefix to parameters, so you can use 'author' to filter for parameters such as 'author.name'.

Note that if an empty List or no List is provided as a value for the include parameter then all statically typed instance properties will be subject to binding if they are not explicitly excluded. See the bindable constraint documentation for more information on how to control what is bindable and what is not.

The underlying implementation uses Spring’s Data Binding framework. If the target is a domain class, type conversion errors are stored in the errors property of the domain class.

Refer to the section on data binding in the user guide for more information.