Wicket in Action

Groovy DSL for Apache Wicket

26 May 2014, by dashorst

Eugene Kamenev has released his take on making Wicket groovy:

Apache Wicket is great, and Groovy is also great. This project tries to combine the power of both. However, sometimes Apache Wicket code become damn verbose. But with some little, yet powerful Groovy DSL written, we can extend Wicket to simplify common tasks, and to delete over 30-40% of verbose code.

A short example of the usual Wicket and Java code:

Form form = new Form("wicketForm", new CompoundPropertyModel(this)) {
    public void onSubmit(){
        System.out.println(MyPage.this.input1 + MyPage.this.input2);
    public boolean isVisible() {
        // just for example :)
form.add(new TextField("input1"));
form.add(new TextField("input2"));

These lines of code can be shortened by using Eugene’s Groovy DSL:

use(WicketDSL, WicketFormDSL) {
    def form('wicketForm', 
            new CompoundPropertyModel(this), 
             submit:  { println this.input1 + this.input2 },
             visible: { this.input1 != this.input2 } 
    this << form

You can see some example code in his readme file, and the project comes with some examples.

Go check it out!