API / Apache Wicket Interview questions
How do you create a simple Wicket Link component?
Wicket represents a link as a real component, not a raw <a href="..."> URL string, so clicking it invokes actual Java code rather than navigating to a pre-baked address.
The most common case uses Link<Void>, overriding its abstract onClick() method:
| Java | HTML |
add(new Link<Void>("details") { public void onClick() { setResponsePage(DetailsPage.class); } }); | <a wicket:id="details">View details</a> |
Wicket rewrites the anchor's href at render time to point at an internal callback URL that, when hit, invokes onClick() on the exact component instance that rendered it. For a link that just needs to navigate to a specific page class without custom logic, BookmarkablePageLink<>("details", DetailsPage.class) is simpler and produces a real, stable bookmarkable URL instead of a callback reference.
More Related questions...