Alex schrieb:
Hi,
we've been using wicket for about a month now, so far so good.
The only complain is about code lisibility, sometimes our constructors
are filled with a lot of code, particurally with all the :
add(new Link("myLink")
{
public void onClick(RequestCycle cycle)
{
// do something here...
}
);
If java had good support for "closures", not just anonymous classes, the
syntax could be much more compact. A closure is a function object that
has access to the lexical environment of when it was created.
A closure could be declared like this:
String {Object t} manipulate;
"String" means that the Closure returns a String.
"Object t" is the only argument.
The definition of a Closure could look like this:
manipulate = {t | return t.toString + "abc"};
The part before "|" is the closure argument "t". The part after "|" is
the body of the closure.
So instead of using anonymous classes and overriding methods like this:
new TextInput("myTextInput") {
@Override
String manipulate(String input) {
return input.toString() + "abc";
}
}
The TextInput could accept a closure:
new TextInput("myTextInput", {t | return input.toString() + "abc"});
The constructor signature:
TextInput(String id, String {Object t} manipulate)
For more information, see the entry on closures in the wiki of the
excellent Martin Fowler:
http://www.martinfowler.com/bliki/Closure.html
[...] So we thought a custom component subclassing Link could force this
> approach :
in constructor :
add(new ReflectionLink("myLink", "myMethod"))
and elsewhere :
public void myMethod() { // do something here ... }
Basically the ReflectionLink would contain some reflection stuff in
onClick(RequestCycle cycle) to invoke our method...
What do you think ?
What about something like this:
html:
<input type="submit" wicket:reflect="onMyAction" />
java:
class X extends WebPage {
@Expose
public void onMyAction() {
System.out.println("myButton klicked");
}
}
Timo
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user