Fork me on GitHub

17 Mar 2010

Customising collection binding in Grails

Following up on my earlier post about using custom PropertyEditor implementations to bind association properties I started looking into the options for custom binding one-to-many associations.

For example, tags, as seen on many sites (including Blogger) would typically be modelled as a Set of either String or some kind of Tag domain object. With tag functionality we really don't want to be selecting tags using a multi-select combo box. It would be ridiculously huge and hard to find anything in it. An auto-completer that recognises commas as delimiters would be the way to go. has an AJAX Autocompleter that can handle this kind of tokenised input. Similarly, the Grails RichUI plugin offers an autocomplete tag that uses a Yahoo! UI component. There are comparable controls available if you're using jQuery or some other Javascript library. What you will end up with is the browser submitting a single parameter containing a comma-separated String of tag names. The trick is to turn that into a collection of String or Tag domain instances.

For the former case binding is pretty easy. All you need is a property editor that converts a comma-separated String into a Set of String and vice-versa:
Then just register the editor in your PropertyEditorRegistrar implementation:
registry.registerCustomEditor List, "tags", new TagListEditor()

If you've gone the latter route and used a domain object to represent a tag things have been trickier. Grails didn't allow you to register custom property editors against one-to-many association properties as it considered it knew how to handle such binding.

I raised and fixed a Grails issue to allow for registering custom editors on one-to-many properties so from 1.2.2 and 1.3-M2 you will be able to use a property editor something like this:


Anonymous said...

Great idea! Love seeing a creative mind work and gain success!!!!!! Hope it continues to grow!


jacksmith said...

Thanks for sharing.I found a lot of interesting information here. A really good post, very thankful and hopeful that you will write many more posts like this one.

acmarket said...

Thankyou for the valuable information.
ac market
pubg apk

apk said...

Thankyou for the valuable information.iam very interested with this one.
looking forward for more like this.
telugu sex stories
telugu boothu kathalu
sex stories

ciwuxi said...

hotmail login

seo company said...

Fast Social Follower will help you increase your visiliblty on social media platform such as Buy Facebook Followers

Puremelda said...

In the quest for quality grades, students have realized the need for working with Nursing Paper Writing Service agencies that specialize in various types of essay writing. They are the best company that handles Best Proofreading Service and Affordable Editing Services.

Jennifer said...

It’s impressive that you are getting thoughts from this article as well as from our argument made at this time.Here is my webpage
shareit for pc
xender for pc

steve said...

شكرا معلومات مفيدة يمكنك زيارة ايضا لمعلومات قيمة اخرى قم بزيارة :

شركة غسيل خزانات بالمدينة المنورة
افضل شركة تنظيف

Puremelda said...

Custom Term Paper Service industry has grown steadily in provision of Legitimate Term Paper Services and high quality Custom Term Paper Writing Services which is preferred by scholars worldwide.

Unknown said...

Nice information shared, good work
Best Friend Status 2020
Love Attitude Status 2020
Hurt Status for Whatsapp
Alone Status for Whatsapp

Open bin file said...

augustwalker said...

When you setup or connect your HP printer with your PC framework, the extremely essential thing you need is the unaffected HP printer driver to hard with the printing procedure. Like the vast majority of the minimal gadgets or machines, HP printer likewise requires reasonable drivers first to introduce inside your framework so as to perform. Be that as it may, you can without much of a stretch download and introduce printer driver from .However, you can generally have the decision to physically download the driver and after that introduce it in your PC framework.

Open bin file said...

Open bin files