Chapter 11: Truth of Models - The soul of Wicket
IModel
IModel<T> abstracts data access for components. It decouples UI elements from storage and retrieval details.
PropertyModel
PropertyModel binds to bean properties and simplifies common form/page bindings.
CompoundPropertyModel
CompoundPropertyModel reduces boilerplate by resolving child component IDs against a shared backing object.
LoadableDetachableModel
Use LoadableDetachableModel when data should be reloaded lazily per request and detached safely to reduce session footprint.
Practical Pitfalls
-
ProblemModel bindings become hard to follow and maintenance gets risky.CauseToo much reliance on implicit compound bindings hides intent and ownership.SolutionMake critical bindings explicit with focused models so intent remains readable.
-
ProblemProperty evaluation behaves differently by lifecycle timing.CauseResolution happens before component hierarchy/context is fully established.SolutionResolve model expressions after hierarchy setup phases.
-
ProblemSession memory grows over time.CauseDetachable model assumptions are broken and heavy references remain alive.SolutionDesign for load-on-demand and detach-at-end-of-request discipline.
-
ProblemFinal values differ depending on edit sequence.CauseMultiple form components mutate one shared model without explicit ordering.SolutionSeparate models by responsibility, or define deterministic update order with tests.