API / Apache Wicket Interview questions
What is a Wicket Behavior?
A Behavior is a reusable, pluggable piece of logic that can be attached to any component to modify how it renders or responds to events, without subclassing that component or touching its own code.
Behaviors hook into the same lifecycle points a component itself does — they can contribute extra HTML attributes (onComponentTag()), add CSS classes conditionally, inject additional JavaScript, or respond to AJAX events, and a single component can have multiple Behaviors attached simultaneously, each contributing its own piece independently. A common built-in example is AttributeAppender, which adds or modifies an HTML attribute (like conditionally appending a "highlighted" CSS class) without requiring a dedicated component subclass just for that one styling tweak.
The design value is composability: instead of creating a new component subclass every time you need slightly different rendering behavior, a Behavior can be written once and attached to any component that needs that specific cross-cutting capability, keeping component class hierarchies from sprawling.
More Related questions...