PageParameterAwareMountedMapper.javaMountedMapper behavior. When a user manually edits a Wicket URL — for example changing /User/4?15 to /User/5?15 — the default mapper prioritizes the page ID query parameter (?15) over the path parameters (/5), causing the user to see the cached page for user 4 instead of a fresh page for user 5. This custom mapper detects mismatches between the cached page's parameters and the current request's parameters, and redirects to a fresh bookmarkable page instance when they differ, ensuring the URL always reflects the actual displayed content.The class extends MountedMapper and overrides only processHybrid() — the method Wicket calls when it has both a page ID (from a session-cached page) and path parameters (from the URL). The override:
processHybrid() to get the default handlerPageExpiredException — if the cached page has expired, falls back to processBookmarkable() which creates a fresh pageRenderPageRequestHandler with a PageProvider that has a page instance, compares: (a) the page class of the cached instance vs. the requested page class, and (b) the cached page parameters vs. the current request parametersprocessBookmarkable() — a fresh, stateless page instance with the correct parametersWicket's MountedMapper implements a "hybrid" strategy: if a page ID exists in the URL (either as ?wicket:pageId=15 or via ?15 shorthand), load the serialized page from the page store; otherwise create a fresh bookmarkable instance. The problem is that once a session has a cached page (say page ID 15 for user 4), subsequent requests with different path parameters but the same page ID will serve the cached page — the mapper never compares the path parameters against the cached page's parameters. URL manipulation by users (or browser history) would display stale data.
Pages are mounted in WicketApplication.init() using mount(new PageParameterAwareMountedMapper("Home", HomePage.class)) instead of mountPage(). This is documented in the class's own Javadoc with a usage example.
| Commit | What changed |
|---|---|
868d6abb7 through ceb63e8a1 | Six annual copyright header updates. The mapping logic itself has been stable since its creation — the URL routing behavior has proven correct for all mounted pages across multiple Wicket version upgrades. |