You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Carl-Eric Menzel <cm...@wicketbuch.de> on 2011/07/21 20:45:02 UTC

A safer way to build PropertyModels

After seeing the LambdaJ-based model idea at
https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-LambdaJ
I thought I'd try and implement something like that in a ready-to-use
fashion, and simplify it a little.

The result is here:
https://github.com/duesenklipper/wicket-safemodel

This is a way to refactor-safely and type-safely build models, without
relying on brittle string literals:

  SomeBean myBean = ...
  IModel<String> childNameModel =
  model(from(myBean).getChild().getName());

No cast, no string literal, only getters. It works with regular
JavaBeans, Lists, and with Maps (string keys only though).

Instead of requiring a compile-time step this does some proxying in the
background to construct a property expression.

Anybody interested please give it a try and let me know of any issues.

Note: If you feel comfortable with configuring an annotation
processor in your Maven build as well as your IDE build, go ahead and
try Igor's metagen [https://github.com/42Lines/metagen]. That way you
don't have any runtime magic.

Use SafeModel if you don't want an additional compile step and do want
(very slightly) less keyboard typing.

Carl-Eric
www.wicketbuch.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A safer way to build PropertyModels

Posted by Carl-Eric Menzel <cm...@wicketbuch.de>.
On Thu, 21 Jul 2011 22:33:47 +0300
Martin Grigorov <mg...@apache.org> wrote:

> Matt,
> 
> You need first class functions.
> All cool JVM langs support them. Just peek your favorite.

That is indeed true.

However, just for the fun of it, I'm going to try and implement at
least a limited version of this... :-)

Carl-Eric
www.wicketbuch.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A safer way to build PropertyModels

Posted by Martin Grigorov <mg...@apache.org>.
Matt,

You need first class functions.
All cool JVM langs support them. Just peek your favorite.

On Thu, Jul 21, 2011 at 10:17 PM, Matt Brictson <ma...@55minutes.com> wrote:
> This looks fantastic. Can you think of an elegant way to use similar syntactic sugar to create LoadableDetachableModels as well?
>
> For example:
>
> // This would return a PropertyModel
> model(from(myBean).getChild().getName());
>
> // This a LoadableDetachableModel
> loadedModel(from(myService).listUsers());
>
> // Which is more concise than
> new LoadableDetachableModel<List<User>> {
>  protected List<User> load() {
>    myService.listUsers();
>  }
> }
>
> On Jul 21, 2011, at 11:45 AM, Carl-Eric Menzel wrote:
>
>> After seeing the LambdaJ-based model idea at
>> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-LambdaJ
>> I thought I'd try and implement something like that in a ready-to-use
>> fashion, and simplify it a little.
>>
>> The result is here:
>> https://github.com/duesenklipper/wicket-safemodel
>>
>> This is a way to refactor-safely and type-safely build models, without
>> relying on brittle string literals:
>>
>>  SomeBean myBean = ...
>>  IModel<String> childNameModel =
>>  model(from(myBean).getChild().getName());
>>
>> No cast, no string literal, only getters. It works with regular
>> JavaBeans, Lists, and with Maps (string keys only though).
>>
>> Instead of requiring a compile-time step this does some proxying in the
>> background to construct a property expression.
>>
>> Anybody interested please give it a try and let me know of any issues.
>>
>> Note: If you feel comfortable with configuring an annotation
>> processor in your Maven build as well as your IDE build, go ahead and
>> try Igor's metagen [https://github.com/42Lines/metagen]. That way you
>> don't have any runtime magic.
>>
>> Use SafeModel if you don't want an additional compile step and do want
>> (very slightly) less keyboard typing.
>>
>> Carl-Eric
>> www.wicketbuch.de
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A safer way to build PropertyModels

Posted by Matt Brictson <ma...@55minutes.com>.
This looks fantastic. Can you think of an elegant way to use similar syntactic sugar to create LoadableDetachableModels as well?

For example:

// This would return a PropertyModel
model(from(myBean).getChild().getName());

// This a LoadableDetachableModel
loadedModel(from(myService).listUsers());

// Which is more concise than
new LoadableDetachableModel<List<User>> {
  protected List<User> load() {
    myService.listUsers();
  }
}

On Jul 21, 2011, at 11:45 AM, Carl-Eric Menzel wrote:

> After seeing the LambdaJ-based model idea at
> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-LambdaJ
> I thought I'd try and implement something like that in a ready-to-use
> fashion, and simplify it a little.
> 
> The result is here:
> https://github.com/duesenklipper/wicket-safemodel
> 
> This is a way to refactor-safely and type-safely build models, without
> relying on brittle string literals:
> 
>  SomeBean myBean = ...
>  IModel<String> childNameModel =
>  model(from(myBean).getChild().getName());
> 
> No cast, no string literal, only getters. It works with regular
> JavaBeans, Lists, and with Maps (string keys only though).
> 
> Instead of requiring a compile-time step this does some proxying in the
> background to construct a property expression.
> 
> Anybody interested please give it a try and let me know of any issues.
> 
> Note: If you feel comfortable with configuring an annotation
> processor in your Maven build as well as your IDE build, go ahead and
> try Igor's metagen [https://github.com/42Lines/metagen]. That way you
> don't have any runtime magic.
> 
> Use SafeModel if you don't want an additional compile step and do want
> (very slightly) less keyboard typing.
> 
> Carl-Eric
> www.wicketbuch.de
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A safer way to build PropertyModels

Posted by Iain Reddick <ia...@beatsystems.com>.
I LOLed at this:

"Unfortunately, most of us are stuck in Java world where proper functions are still considered science fiction like flying cars and World Peace."

----- Original Message -----
From: "Carl-Eric Menzel" <cm...@wicketbuch.de>
To: users@wicket.apache.org
Sent: Thursday, 21 July, 2011 7:45:02 PM
Subject: A safer way to build PropertyModels

After seeing the LambdaJ-based model idea at
https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-LambdaJ
I thought I'd try and implement something like that in a ready-to-use
fashion, and simplify it a little.

The result is here:
https://github.com/duesenklipper/wicket-safemodel

This is a way to refactor-safely and type-safely build models, without
relying on brittle string literals:

  SomeBean myBean = ...
  IModel<String> childNameModel =
  model(from(myBean).getChild().getName());

No cast, no string literal, only getters. It works with regular
JavaBeans, Lists, and with Maps (string keys only though).

Instead of requiring a compile-time step this does some proxying in the
background to construct a property expression.

Anybody interested please give it a try and let me know of any issues.

Note: If you feel comfortable with configuring an annotation
processor in your Maven build as well as your IDE build, go ahead and
try Igor's metagen [https://github.com/42Lines/metagen]. That way you
don't have any runtime magic.

Use SafeModel if you don't want an additional compile step and do want
(very slightly) less keyboard typing.

Carl-Eric
www.wicketbuch.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org