API / Apache Wicket Interview questions
What is a Wicket Fragment?
A Fragment lets a piece of markup that lives inside a parent page or panel's own HTML file be reused as if it were a small standalone component, without creating a separate Java class and separate HTML file the way a Panel requires.
It's declared with a <wicket:fragment wicket:id="..."> block sitting anywhere in the parent's markup, and instantiated in Java with new Fragment("targetId", "fragmentId", parentMarkupProvider), which tells Wicket to pull that specific fragment's markup and drop it wherever targetId is placed — commonly used to swap between two small variants of the same area of a page (say, an "edit" fragment versus a "view" fragment) without maintaining two separate Panel classes.
The practical rule of thumb: reach for a Fragment when the reusable markup is small and only used within one parent's own template; reach for a Panel once it needs to be shared across multiple different pages or gets complex enough to deserve its own file.
More Related questions...