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
-
ProblemA hidden component never comes back after AJAX toggle.CauseNo DOM placeholder exists while hidden, so AJAX has no update anchor.SolutionEnable placeholder output for visibility-toggled components.
-
ProblemChange events never trigger server logic.CauseEvent name does not match current Wicket expectations (legacy naming left behind).SolutionUse version-correct event names and verify behavior after upgrades.
-
ProblemFirst click does nothing, second click works.CauseDOM/event conflicts or JavaScript errors interfere with behavior binding.SolutionCheck browser console, propagation path, and actual binding target first.
-
ProblemAfter session timeout, UI appears frozen.CauseAJAX call receives normal redirect handling, not AJAX-specific recovery flow.SolutionImplement AJAX-aware timeout handling and route users back to login cleanly.
-
ProblemUsers get stuck when stale page exceptions occur.CauseNo user-facing recovery message or reload path is provided.SolutionCatch and explain the state issue, then guide users to reload or retry safely.
-
ProblemAdding custom jQuery AJAX increases stale errors.CauseCustom calls hit Wicket-managed page URLs and break render count consistency.SolutionMove custom calls to dedicated endpoints separated from page-state URLs.
-
ProblemjQuery plugins work on first render but fail after partial updates.CausePlugin initialization is not re-run after DOM replacement.SolutionRe-initialize plugins explicitly after AJAX updates.
-
ProblemCustom input components throw hierarchy/update errors in AJAX flows.CauseDisabled/hidden states remove expected update anchors.SolutionApply placeholder output rules consistently to custom components too.