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

Reply via email to