Anonymous inner class in groovy

I am considering groovy-wicket integration and the lack of anonymous inner classes seems to be a problem when writing event handlers. Is there a more attractive way to write this code.

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"}
}
+3
source share
5 answers

Maybe I'm wrong, but this is not what WickeBuilder is trying to solve :

The Wicket Builder utility implements a Groovy Builder to build Gate component trees.

, Groovy . . Groovy Wicket, , , . , .

WicketBuilder Closures. , , . builder , .

[...]

+1

Ermh.. "" , , , "" Groovy:

Groovy

+1

Groovy 1.7 . . groovy 1.7 .

0

Source: https://habr.com/ru/post/1717984/


All Articles