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...
@NotNull
String creditCard;
}
...at compile-time Groovy generates this:
@NotNull
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...
config="org.metawidget.inspector.impl.BasePropertyInspectorConfig">
<propertystyle>org.metawidget.inspector.impl.propertystyle.groovy.GroovyPropertyStyle</propertystyle>
</propertytypeinspector>
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.
2 comments:
And it gets even better when Groovy 1.6 is released, thanks to @Bindable
http://shemnon.com/speling/2008/04/bindable-observable-properties.html
Andres,
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!
Richard.
Post a Comment