GroovyBinder Plugin

  • Tags : scaffolding, templating, binding
  • Latest : not provided
  • Last Updated: 31 December 2009
  • Grails version : *
  • Authors : Marc Palmer
1 vote
Dependency :
compile ":groovybinder:not provided"

Summary

Description

This plugin is deprecated by scaffolding functionality in 1.1, and ScaffoldTags plugin - http://grails.org/plugin/scaffold-tags

GroovyBinder Plugin

For those who would like to have binding of many-type associations… Here's a simple plugin to provide dynamic write-only "values" property and a remove() method that works for many-type associations, written using Groovy.

I wrote this largely because of an upcoming ScaffoldTags plugin. But I had to replace the whole binding mechanism in order to support this functionality with minimal impact to the developer. Hopefully we won't need this plugin in a near-future release. But for those on 0.4.2 at least, you may find this useful.

Author: Daiji Takamori - http://grails.snowmochi.com Plugin Package: http://grails.snowmochi.com/grails-GroovyBinder-0.1.zip

  • This does not support multipart requests (i.e. file uploads) yet.
  • If you already have a property named "values" in your domains, or a method named "remove", you will need to modify the plugin code that sets this up in order to avoid incompatibilities. See bottom.
This doesn't have a mechanism for many-type associations to bind to multiple objects that you'd like to edit or create on a single request (i.e. if you'd like to edit all your Address lists simultaneously)

Installation

From the command-line run the following:

grails install-plugin path/to/grails-GroovyBinder-0.1.zip
If you don't have the scaffolding templates installed and you are willing to auto-generate (or re-generate) your controllers (WARNING- if you already have custom code in your controller that you can't afford to lose, DON'T do this), from the command line, run the following script:
grails install-groovy-binder
If you already have the scaffolding templates installed or you would like to modify an existing controller without rewriting it, in the Controller template, replace the following lines in save() and update():
${propertyName}.properties = params
with the following line:
${propertyName}.values = params

Documentation

In order to submit a many relationship, simply submit multiple values for the propertyname.id value, instead of only a single value. You can also submit a single comma-separated value.

This plugin supports a more flexible date-handling format than the core binding code. While it does support the standard date mechanisms, it also supports passing in dates specified as property_format and property_values, where property_values should be a multi-valued parameter and property_format specifies the keys of the parameters in the order they are specified in property_values, using the character codes used by java.text.SimpleDateFormat.

If you already have a values property (or setValues method) or a remove method:

The dynamic binding is done in GroovyBinderGrailsPlugin in the lines that contain the following two strings:

domainClass.metaClass.remove
and
domainClass.metaClass.setValues
You'll want to give them new names. "setProperties" didn't work for me.