I've posted this in the wicket-bootstrap slack channel at the-asf.slack.com:
I'm interested in modernizing the Wicket API for component composition and databinding to make use of modern Java APIs, and to make Wicket less verbose. Even though anonymous inner classes are very memory efficient compared to keeping references for all handlers, they are pretty bad for readability and understandability of the code. Currently building/adding a link to a page is this: ``` add(new Link<>("hello") { private static final long serialVersionUID = 1L; @Override protected void onConfigure() { super.onConfigure(); setVisible(true); setEnabled(true); } @Override public void onClick() { System.out.println("Hello, World!"); } }); ``` An example of a more modern approach could look like this: add(ComponentBuilder.link("hello") .visibleWhen(() -> true) .enabledWhen(() -> true) .onClick(() -> System.out.println("Hello, World!")) .build()); However this would require adding a bunch of references, and much increased memory usage. There are more issues, for example the `this` pointer is different (e.g. not the component or behavior). There are certainly gotchas, but it is worth exploring. Martijn On Tue, Jul 15, 2025 at 12:55 PM Richard Eckart de Castilho <r...@apache.org> wrote: > Hi all, > > as far as I know, subclassing is a main part of the Wicket development > process. > For most stuff, it seems necessary to define named or anonymous subclasses > to > define behavior. I find this very verbose. > > For some time now, I have been compiling a bunch of "Lambdaized" Wicket > classes > in one of my projects and coding with them feels -at least to me- much > cleaner. > > Consider for example: > > .Different kinds of behaviors > ``` > import static ... LambdaBehavior.visibleWhen; > > var editor = new DropDownChoice<Pair<String, String>>("dropdown"); > editor.add(visibleWhen(() -> editor.getChoices().size() > 1)); > ``` > > .Components using callbacks instead of method overriding > ``` > var form = new LambdaForm<AnnotationEditorState>("form", state); > form.onSubmit(this::actionSave); > > form.add(new LambdaAjaxButton<>("button" > this::actionClearSkippedRecommendations)); > ``` > > .Behaviors using lambdas instead of method overriding > ``` > .add(new LambdaClassAttributeModifier(classes -> { > if (stats.getNewAnnotations() == 0) { > classes.add("text-opacity-25"); > } > return classes; > }))); > ``` > > You can find the implementations here: > > > https://github.com/inception-project/inception/tree/main/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/lambda > > In general, I think I would prefer a more "verb" oriented style especially > for behaviors, > e.g. instead of new LambdaClassAttributeModifier(...) use a static > modifiyClassAttribute(...). The LambdaBehavior already has that, but some > of > its static methods (e.g. onConfigure) currently clash with Component > methods > preventing a static import. > > What do you think of that style? > Is that something you'd find interesting for including in Wicket proper? > > Cheers > > -- Richard > > -- Become a Wicket expert, learn from the best: http://wicketinaction.com