Monday, June 16, 2008

Metawidget gets Groovy

Update: the APIs shown in this blog entry have changed slightly in newer releases of Metawidget. Specifically <propertystyle> now takes a PropertyStyle instance, not a class name. Please download the latest documentation from

The latest release of Metawidget adds supports for Groovy. This means Metawidget's Inspectors can now inspect GroovyBean properties for types and annotations.

GroovyBean properties are similar to JavaBean's getters/setters. Indeed, at compile time, GroovyBean properties try to 'look' like JavaBean properties by automatically generating a private member variable and a public getter/setter.

So, if your Groovy code says this...

class Booking {
   String creditCard;
} compile-time Groovy generates this:

class Booking {
   private String mCreditCard;

   public String getCreditCard() {
      return mCreditCard;

   public void setCreditCard(String creditCard) {
      mCreditCard = creditCard;

Notice, however, that the annotation stays on the private member variable - it does not get applied to the getter. There are good reasons for this, but it means Metawidget's native JavaBeanPropertyStyle cannot be used to find those annotations.

So, instead, Metawidget now has a pluggable GroovyPropertyStyle that understands Groovy properties natively. To use it, you just need to update your inspector-config.xml...

<propertytypeinspector xmlns="java:org.metawidget.inspector.propertytype"

How does this work in practice? See for yourself! The Metawidget download includes a Seam Groovy Booking sample application, that showcases using Metawidget with Groovy. It's covered in detail in the reference guide.


Andres Almiray said...

And it gets even better when Groovy 1.6 is released, thanks to @Bindable

Richard said...


Wow - yes, I had not heard of @Bindable coming in Groovy 1.6, but that should be very useful indeed.

Hopefully it'll 'just work' using Metawidget's new GroovyPropertyStyle, but I look forward to testing it when it comes out!