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/28 12:12:19 UTC

A safer way to build PropertyModels, version 1.2

https://github.com/duesenklipper/wicket-safemodel

As I wrote earlier on this list, SafeModel lets you turn the fragile
strings of this:

IModel<String> childNameModel = new PropertyModel<String>(
    myBean, "child.name");

...into this, gaining refactor-safety:

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

I have just built SafeModel version 1.2, with the following
improvements:

- fixed an oversight in the initial version: You can now use a model as
  your root object for the from() method.

- Based on an idea from Matt Brictson, you can now quickly build
  LoadableDetachableModels using fromService instead of from:

  IModel<User> userModel = model(fromService(userEJB.loadUser(42)));

  This is experimental. fromService may be refactored later to end up
  in a different class (but that would at worst force you to change
  imports, so no big deal really).

As always, feedback is greatly appreciated!

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, version 1.2

Posted by Carl-Eric Menzel <cm...@wicketbuch.de>.
On Thu, 28 Jul 2011 12:44:14 +0200
Thomas Matthijs <li...@selckin.be> wrote:

> > ...into this, gaining refactor-safety:
> >
> > IModel<String> childNameModel =
> > model(from(myBean).getChild().getName());
> >
> >
> 
> Does it require a default constructor?

In the above example, myBean is any sort of regular Java bean. That
means: regular getters and setters. Default constructors may not be
needed, I did not test that. SafeModel does not instantiate your
objects. PropertyModel (which is what I'm using under the hood) may run
into issues, but I'd suggest just giving it a shot. It will fail
quickly if it doesn't work :)

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, version 1.2

Posted by Thomas Matthijs <li...@selckin.be>.
On Thu, Jul 28, 2011 at 12:12 PM, Carl-Eric Menzel <cm...@wicketbuch.de>wrote:

>
> https://github.com/duesenklipper/wicket-safemodel
>
> As I wrote earlier on this list, SafeModel lets you turn the fragile
> strings of this:
>
> IModel<String> childNameModel = new PropertyModel<String>(
>    myBean, "child.name");
>
> ...into this, gaining refactor-safety:
>
> IModel<String> childNameModel =
> model(from(myBean).getChild().getName());
>
>

Does it require a default constructor?

Re: A safer way to build PropertyModels, version 1.2

Posted by Carl-Eric Menzel <cm...@wicketbuch.de>.
On Thu, 28 Jul 2011 09:04:31 -0700
"Matt Brictson" <ma...@55minutes.com> wrote:

> On Jul 28, 2011, at 3:12 AM, Carl-Eric Menzel wrote:
> 
> > IModel<User> userModel = model(fromService(userEJB.loadUser(42)));
> 
> Not sure if this is a typo in your example, but wouldn't this mean
> that (the real, non-proxied) userEJB.loadUser is invoked when the
> model is constructed? Perhaps this syntax is correct:
> 
> model(fromService(userEJB).loadUser(42));

You are correct on both counts. That was a typo in my example. I fixed
it on the github page now.

Thanks
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, version 1.2

Posted by Matt Brictson <ma...@55minutes.com>.
On Jul 28, 2011, at 3:12 AM, Carl-Eric Menzel wrote:

> IModel<User> userModel = model(fromService(userEJB.loadUser(42)));

Not sure if this is a typo in your example, but wouldn't this mean that (the real, non-proxied) userEJB.loadUser is invoked when the model is constructed? Perhaps this syntax is correct:

model(fromService(userEJB).loadUser(42));


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