-
Notifications
You must be signed in to change notification settings - Fork 298
LazyModel
svenmeier edited this page Feb 18, 2013
·
10 revisions
A type-safe model implementation for Apache Wicket, supporting:
- lazy evaluation of method invocations
- arbitrary parameters
- generics
- collections
- interfaces
A a = ...;
IModel<B> model = model(from(a).getB());
... or starting from a model:
IModel<A> a = ...;
IModel<List<String>> model = model(from(a).getB().getStrings());
... or as a LoadableDetachableModel:
IModel<A> a = ...;
IModel<String> model = model(from(a).getB().getStrings().get("key")).loadableDetachable();
Evaluations can be nested too:
IModel<A> a = ...;
IModel<D> d = ...;
IModel<C> model = model(from(a1).getB().getCs().get( from(d).getIndex() ));
DataTables columns can be lazily evaluated too:
column = new LazyColumn<A, B>(header, from(A.class).getB());
LazyModel has to proxy all evaluation results, thus if you're concerned about performance you might want to cache lazy evaluations:
private static final IModel<B> B = model(from(A.class).getB());
IModel<A> a = ...;
add(new TextField<B>("b", B.bind(a));
Inspired by:
- https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-LambdaJ
- https://github.com/duesenklipper/wicket-safemodel
- http://wicketeer.org/wicket-modelfactory
Using: