Grails multiple select binding

When first time I try to use html select tag with multiple selection, I spent about 1h to figure "how to" because user guide is, hmmm, as is. So, there is my little example:

Lets create domain objects:

  1.  
  2. Author {
  3. String firstName
  4. String lastName
  5. static hasMany = [books:Book]
  6. }
  7.  
  1.  
  2. String title
  3. static belongsTo = [author:Author]
  4. }
  5.  

Author form will contain select with books like this:

  1.  
  2. <g:select optionKey="id" optionValue="title" multiple="multiple" name="author.books" id ="author_books" from="${allBooks}" value="${authorInstance?.books*.id}"/>
  3.  

Multiple select binding to Author.books is now available.

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.