Category Archives: tech

Better structured date editor for Grails

It’s really surprising and annoying that the default structured editor for dates and times in Grails is so limited. It only allows one to edit (or enter) time information down to the minute. Seconds and smaller are ignored, even though the editor specifically returns an epoch time in milliseconds with the getTime() method! The default editor also only works for java.util.Date and java.sql.Date — not the also common java.sql.Timestamp.

I’ve created a new editor that works for all 3 types mentioned and allows one to edit/enter more complete time information, including seconds (yeah!), millisecond or nanosecond, and also allows the use of an “epoch” time field to edit a raw integer.
Continue reading

mysql history munging

At work, I run the mysql clients on multiple hosts with multiple versions. My home directory is a network mount and thus my .mysql_history file is shared between all these hosts. Often the command history gets weirdly munged, with spaces converted to \040 — the character sequence for the octal escape code for ASCII space. Here’s a little workaround/fix:

/bin/sed 's/\\040/ /g;' ~/.mysql_history > ~/
/bin/mv -f ~/ ~/.mysql_history

Make that into an alias or script. Just make sure you quit all instances of the mysql client before running. Then when you restart, the history should get reloaded correctly.

I haven’t bothered to figure out why this is happening, i.e. what the version problems are or 32/64 bit or readline/editline or the sequence of starting multiple clients on multiple hosts…

CKEditor spellchecker.jsp

Here is a JSP version of the server-side script needed for the CKEditor plugin for aspell. It was inspired by/based upon a post in the forums. I’ve made some mods to get it to work, be more complete, and be more like the current perl version, with fixes recommended in the main thread. It’s not fully tested but hopefully it will help somebody.

Note that for best results, you will need Apache Commons Lang. You can comment out that code but then you’ll get false-positive misspellings of partial words before and after the HTML entities.

Install the attached file as .../aspell/spellerpages/server-scripts/spellchecker.jsp


Grails standalone classes need package

I was reminded again today that standalone classes in Grails must belong to a package. That is, a class in src/groovy or src/java needs to be in a package. For example:

file: src/groovy/mypackage/MyClass.groovy

package mypackage
class MyClass { ... }

If the class is without a package (appearing as src/groovy/MyClass.groovy), it will compile correctly but no Grails classes (like your controller or service) will be able to find it, generating an org.codehaus.groovy.control.MultipleCompilationErrorsException with the message unable to resolve class MyClass

GORM nullables and unsaved transient instance

I have nullable one-to-many relations in Grails/GORM and started getting “object references an unsaved transient instance” exceptions from Hibernate. In the Grails forms, selecting a blank/no-selection value for the field sent''. GORM then tries to create a new empty object and during the save(flush:true), it complains with the exception:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: MyOtherClass

This stackoverflow answer gave me the clue about params and I now remove the nullable field from params when it’s blank.

def myObject = MyClass.get(
if (null == || '' == {
        myObject.myOtherObject = null
        } = params
if (!myObject.hasErrors() && true)) {

Groovy (Grails) markup builder for select/option menu

I was trying to use the Groovy XML MarkupBuilder to have Grails output an HTML fragment for an AJAX call and just couldn’t get it to work. I wanted to generate an HTML select/option menu from a list of lists:

assert results == [[null,null], [17, 'foo'], [42, 'bar'], [69, 'bahz']]

(That list was returned from a Hibernate Criteria Builder with some specialized projections.)

First I tried to do it simply, following Grails docs:
Continue reading