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

  • Problem
    Model bindings become hard to follow and maintenance gets risky.
    Cause
    Too much reliance on implicit compound bindings hides intent and ownership.
    Solution
    Make critical bindings explicit with focused models so intent remains readable.
  • Problem
    Property evaluation behaves differently by lifecycle timing.
    Cause
    Resolution happens before component hierarchy/context is fully established.
    Solution
    Resolve model expressions after hierarchy setup phases.
  • Problem
    Session memory grows over time.
    Cause
    Detachable model assumptions are broken and heavy references remain alive.
    Solution
    Design for load-on-demand and detach-at-end-of-request discipline.
  • Problem
    Final values differ depending on edit sequence.
    Cause
    Multiple form components mutate one shared model without explicit ordering.
    Solution
    Separate models by responsibility, or define deterministic update order with tests.