Chapter 8: AJAX Divine Power - Change the page without breaking it

AjaxRequestTarget

AjaxRequestTarget is the vessel for partial updates. Add components to target, and Wicket rerenders only those fragments.

AJAX Components

Use AjaxLink, AjaxButton, and AJAX behaviors to trigger server-side logic while preserving page context.

AJAX Form Submit

Combine validation and partial feedback updates for responsive forms without full page refresh.

Dynamic Visibility

Set setOutputMarkupPlaceholderTag(true) when components may toggle visibility through AJAX.

Practical Pitfalls

  • Problem
    A hidden component never comes back after AJAX toggle.
    Cause
    No DOM placeholder exists while hidden, so AJAX has no update anchor.
    Solution
    Enable placeholder output for visibility-toggled components.
  • Problem
    Change events never trigger server logic.
    Cause
    Event name does not match current Wicket expectations (legacy naming left behind).
    Solution
    Use version-correct event names and verify behavior after upgrades.
  • Problem
    First click does nothing, second click works.
    Cause
    DOM/event conflicts or JavaScript errors interfere with behavior binding.
    Solution
    Check browser console, propagation path, and actual binding target first.
  • Problem
    After session timeout, UI appears frozen.
    Cause
    AJAX call receives normal redirect handling, not AJAX-specific recovery flow.
    Solution
    Implement AJAX-aware timeout handling and route users back to login cleanly.
  • Problem
    Users get stuck when stale page exceptions occur.
    Cause
    No user-facing recovery message or reload path is provided.
    Solution
    Catch and explain the state issue, then guide users to reload or retry safely.
  • Problem
    Adding custom jQuery AJAX increases stale errors.
    Cause
    Custom calls hit Wicket-managed page URLs and break render count consistency.
    Solution
    Move custom calls to dedicated endpoints separated from page-state URLs.
  • Problem
    jQuery plugins work on first render but fail after partial updates.
    Cause
    Plugin initialization is not re-run after DOM replacement.
    Solution
    Re-initialize plugins explicitly after AJAX updates.
  • Problem
    Custom input components throw hierarchy/update errors in AJAX flows.
    Cause
    Disabled/hidden states remove expected update anchors.
    Solution
    Apply placeholder output rules consistently to custom components too.