我正在研究groovy-wicket集成,并且在编写事件处理程序时缺少匿名内部类似乎是一个问题.
有没有更时髦的方式编写此代码
import org.apache.wicket.PageParameters
import org.apache.wicket.markup.html.basic.Label
import org.apache.wicket.markup.html.link.Link
import org.apache.wicket.markup.html.WebPage
/**
* Homepage
*/
class HomePage extends WebPage {
public HomePage(final PageParameters parameters) {
// Add the simplest type of label
add(new Label("message", "Wicket running!"));
def link1 = new ClickHandler("link1") //in java, defined inline
add(link1);
}
}
class ClickHandler extends Link{
ClickHandler(String id) {
super(id);
}
void onClick(){println "Hi"}
}
解决方法:
我可能是错的,但这不是WickeBuilder试图解决的问题:
The Wicket Builder utility implements
a Groovy Builder for constructing
Wicket Component trees.While using the builder makes building
Component trees easier and more clear
to the reader, the original driver was
the fact that Groovy does not allow
anonymous inner classes. Wicket
relies on overriding methods to
provide custom functionality for many
Component types. Groovy can be used
to code Wicket page classes, but each
class that is overridden needs a named
class definition. Possible, but
clunky.The WicketBuilder simulates these
overrides with named Closures.
Closures are, essentially, portable
code blocks. Under the hood, the
builder creates dynamic class
overrides and runs the closures when
the named method is called.[…]
原文地址:https://codeday.me/bug/20191210/2102060.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。