Sometimes all the clever stuff in the world can't get you past something seemingly simple. I'm still plugging away on my groovy/wicket builder implementation. In order to emulate anonymous inner classes I pass a closure to the builder, with the same name as the overridden method. An example:
Java:
add(new Form("someForm"){
protected void onSubmit()
{
//Do something
}
}
Groovy:
form("someForm", onSubmit:
{
//Do something
}
)
Under the hood, I generate a new class that overrides the base class (in this case, wicket.markup.html.form.Form). The method is overridden. The overridden method calls the Closure. Complicated? Yeah, but functional.
Well, almost functional. There's one little thing (so far) that doesn't work. It looks like the following:
form("someForm", onSubmit:
{
super.onSubmit()
}
)
Since the class under the hood overrides 'onSubmit', you can't use 'this'. From what I can gather, there's no way to call 'super' through reflection. I tried several different things, but in the interest of getting on with life, I made a shortcut. Each method that is overridden will now have another method that looks as follows:
[access] [return] super_[method name]([params])
{
super.[method name]([params])
}
An example:
protected void super_onSubmit()
{
super.onSubmit()
}
Hey. It works.
I've been out for a few days. Checking with sourceforge again...
Friday, March 16, 2007
Subscribe to:
Post Comments (Atom)
1 comment:
Heya. Good to see you're trying to make something nice out of Wicket/ Groovy integration.
I see you're waiting for Sourceforge. Wouldn't you be interested in putting your project in Wicket-stuff instead? You would have the green light to take that project anywhere you would like it, replacing the current one. It might be easier for people to find your project and it might be easier to let more people work on your project as well.
Anyway, whatever you do, please mention your project on the Wicket WIKI and consider putting it in our Bamboo server as well.
Happy coding!
Post a Comment