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.

Prepare Grails hosting: Apache + Tomcat

My last weekend I spent fighting with my VPS, try to configure it to host Grails applications on Tomcat server. Because there are some applications writed in PHP already on it, there is no way to bring tomcat on the front (port 80). Only way is to use Apache2 server as a proxy for Tomcat.

Our work we start from installing Apache HTTP Server (v. 2.2):

  1.  
  2. sudo apt-get install apache2
  3.  

Next step is to install Apache Tomcat. To avoid problems after apt-get tomcat installation, try this tutorial.

Now we ready to download mod_jk that will act as bridge between two servers

  1.  
  2. sudo apt-get install libapache2-mod-jk
  3.  

now configure it:

/etc/apache2/mods-available/jk.conf

JkWorkersFile      /etc/apache2/workers.properties
JkLogFile          "|/usr/sbin/rotatelogs /var/log/apache2/mod_jk.log 86400"
JkLogLevel         info
JkLogStampFormat   "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"
JkOptions          +ForwardKeySize +ForwardURICompat -ForwardDirectories

/etc/apache2/workers.properties

worker.list=tomcat6

worker.tomcat6.type=ajp13
worker.tomcat6.host=localhost
worker.tomcat6.port=8009

and create link to jk.conf:

  1.  
  2. ln -s /etc/apache2/mods-available/jk.conf /etc/apache2/mods-enabled/jk.conf
  3.  

Now we may configure virtual host in Apache:

  1.  
  2. <virtualHost *:80>
  3. ServerName grailsappliaction.com
  4. LogLevel warn
  5. ServerSignature On
  6. JkMount /* tomcat6
  7. </virtualHost>
  8.  

and set tomcat host (conf/server.xml):

  1.  
  2. ...
  3.  
  4. <host name="grailsappliaction.com" appBase="/path/to/grails/app">
  5.  
  6. ...
  7.  

Deploy your grails application in appBase as default (ROOT) application and restart Apache and Tomcat. Your application should be online now.

You may removed this line from tomcat server.xml file, to avoid direct request on 8080 port:

  1.  
  2. ...
  3.  
  4. <connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
  5.  
  6. ...
  7.  

If there is better way to configure Apache and Tomcat, please let mi know.

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