On Fri, Mar 11, 2016 at 10:33 PM, Sven Meier <[email protected]> wrote:
> Hi,
>
> I don't like to add additional classes and/or longer class names. Neither
> should we deprecate any 'old' solutions.
> I'm not keen on the Component#on(String, AjaxListener) method either.
>
> My idea:
> 3)
>
> public static AjaxEventBehavior lambda(String event,
> WicketConsumer<AjaxRequestTarget> consumer) {
> return new AjaxEventBehavior(event) {
> @Override
> protected void onEvent(AjaxRequestTarget target)
> {
> consumer.accept(target);
> }
> };
> }
>
I like it!
The method name could be 'onEvent' though. This way one could import it
statically together with 'onUpdate' from AjaxFormComponentUpdatingBehavior
and 'onUpdateChoice' from AFCCUB.
>
> Usage:
>
> public MyPanel(String id) {
> super(id);
>
> label = ...;
> label.add(AjaxEventBehavior.lambda("click", this::onDoAjax);
> }
>
> private void onDoAjax(AjaxRequestTarget target) { ... }
>
>
>
> Sven
>
>
>
> On 11.03.2016 21:45, Martin Grigorov wrote:
>
>> Hi,
>>
>> I'd like to ask you for your opinion on the following options:
>>
>> 1) introduce java.util.function.Consumer in the existing components and
>> behaviors
>> Example:
>>
>> https://github.com/apache/wicket/blob/lambdas-ajax/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java
>>
>> Pros:
>> - reuse the same components/behaviors as before
>>
>> Cons:
>> - the components/behaviors are no more abstract and the developer may
>> forget to add implementation, i.e. provide consumer or override #onXyz()
>> method
>>
>> 2) introduce new components and behaviors
>> Example:
>>
>> https://github.com/apache/wicket/blob/lambdas-ajax-L/wicket-core/src/main/java/org/apache/wicket/ajax/LAjaxEventBehavior.java
>>
>> Pros:
>> - more cleaner API
>>
>> Cons:
>> - yet another class for the same functionality
>> - a bit uglier name. Whatever name I imagine doesn't sound better than the
>> name of the original class
>>
>> 3) 2) but in separate module (e.g. wicket-java8)
>>
>> 4) 2) but in WicketStuff project
>>
>> 5) Other ideas ?
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>>
>