Archive

Posts Tagged ‘cglib’

Leveraging CGLIB Proxies with Wicket

February 7th, 2008

Anyone that’s spent some time with Java has made use of reflection, which can be loosely defined as Java’s ability to programmatically interrogate a class and call methods on it. Reflection is typically used in frameworks to call property accessors. Within Wicket, reflection is used to retrieve and populate properties using the PropertyModel. Suppose you’ve got a Person class with two properties: firstName and lastName, with the relevant accessors. Your PropertyModel would look like:

Easy enough, right? Where the process breaks down is the string referring to the firstName property. What if the property changes? You won’t know until you try the page or your unit test fails. This is where CGLIB comes in.

A Wicket user working on a project came up with the idea to use CGLIB proxies to bind object properties to components, taking you from this:

to this:

It’s slightly more verbose, but it allows you to know if your property names have changed at compile-time rather than runtime.

Is this in Wicket yet? No, it was just brought up on the Wicket list yesterday, but a number of people are excited about it. It will likely end up in an extension or Wicket-Stuff rather than the core framework. You can follow the discussion here: http://www.nabble.com/CompoundModel-based-on-proxies-td15317807.html

nick Entry ,