Chapter 9: Behavior Secrets - Power without inheritance

What is Behavior?

A Behavior is a reusable capability attached to a component. It lets you extend rendering and event handling without subclassing every UI element.

Lifecycle

Behaviors participate in configuration, rendering, and detachment phases. This makes them suitable for cross-cutting UI concerns.

Use behaviors to register CSS and JavaScript resources near the components that require them.

Custom Behavior

Example
component.add(new AttributeAppender("class", " highlighted"));

Design Rules

Practical Pitfalls

  • Problem
    AJAX behavior never fires.
    Cause
    Event names differ by version and old naming stayed in the code.
    Solution
    Verify event names against your Wicket version and standardize them.
  • Problem
    Event handling is unstable across repeated interactions.
    Cause
    DOM timing and JavaScript issues conflict with behavior binding.
    Solution
    Inspect event propagation and JS errors alongside Wicket behavior code.
  • Problem
    Visibility logic becomes slow and unpredictable.
    Cause
    Heavy checks are placed in high-frequency visibility evaluation paths.
    Solution
    Centralize expensive checks in configure phase and keep visibility checks lightweight.