API / Apache Wicket Interview questions
What is the difference between PropertyModel and CompoundPropertyModel?
Both use reflection to bind a component to a named property of a backing object, but they differ in how many components each one applies to and where the property name comes from.
| PropertyModel | CompoundPropertyModel |
| Attached individually to one component at a time | Attached once to a container (often a Form), applies to all its children |
| Property path given explicitly, e.g. new PropertyModel<>(user, "address.city") | Property path is inferred automatically from each child's wicket:id |
| Good for mixed bindings, or when the property name differs from wicket:id | Good for a form whose fields map cleanly one-to-one with object properties |
A common pattern combines both: set a CompoundPropertyModel on the whole form to save repetitive wiring for most fields, while overriding one field's model explicitly with a plain PropertyModel if its wicket:id doesn't line up cleanly with the underlying property name.
More Related questions...