IModel<String> m =
LoadableDetachableModel
.of(Person::new)
.map(Person::getName);
So much sexiness with lambda's and models...
IModel<Account> a = ...;
IModel<Person> p = a.map(Account::getPerson);
add(new Label("firstName", p.map(Person::getFirstName));
add(new Label("lastName", p.map(Person::getLastName));
Too bad Java doesn't have properties as a language construct. That
would make this even better:
IModel<Account> a = ...;
IModel<Person> p = a.map(Account::person);
add(new Label("firstName", p.map(Person::firstName));
add(new Label("lastName", p.map(Person::lastName));
Martijn
On Thu, Nov 10, 2016 at 1:17 PM, Martin Grigorov <[email protected]> wrote:
> grep Label | grep '::' wicket-examples/src/main/java/
> wicket-examples/src/main/java/org/apache/wicket/examples/
> ajax/builtin/FileUploadPage.java
> 87: form.add(new Label("max", form::getMaxSize));
>
> wicket-examples/src/main/java/org/apache/wicket/examples/
> ajax/builtin/GuestBook.java
> 78: listItem.add(new Label("date", comment::getDate));
>
> wicket-examples/src/main/java/org/apache/wicket/examples/
> compref/LabelPage.java
> 45: add(new Label("dynamicLabel", Date::new));
>
> wicket-examples/src/main/java/org/apache/wicket/examples/
> compref/LinkPage.java
> 48: link1.add(new Label("label1", count1::toString));
>
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Thu, Nov 10, 2016 at 1:05 PM, Emond Papegaaij <[email protected]
>> wrote:
>
>> Didn't we make IModel a functional interface with default methods for
>> setObject and detach? In that case, you can simply use a method reference
>> as
>> your model.
>>
>> Emond
>>
>> On donderdag 10 november 2016 12:56:50 CET Martijn Dashorst wrote:
>> > I'm working on replacing my AROM's and often they just call a getter.
>> > In that case I'd rather use a method reference than doing the IModel
>> > replacement.
>> >
>> > Is there a reason why the LambdaModel doesn't have a path for only a
>> getter?
>> >
>> > This way I can do:
>> >
>> > public A(String p, final SerializableSupplier<Boolean> visibility)
>> > {
>> > this(p);
>> > condition = LambdaModel.of(visibility);
>> > }
>> >
>> > instead of:
>> >
>> > public A(String p, final SerializableSupplier<Boolean> visibility)
>> > {
>> > this(p);
>> > condition = new IModel<Boolean>() {
>> > private static final long serialVersionUID = 1L;
>> >
>> > @Override
>> > public Boolean getObject() {
>> > return visibility.get();
>> > }
>> > };
>> > }
>> >
>> > I have the code ready to push, shall I?
>> >
>> > Martijn
>>
>>
>>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com