API / Apache Wicket Interview questions
When should you use a Panel instead of a Fragment?
Both let you factor out reusable markup and logic, but the deciding factor is scope of reuse and how much the piece has grown on its own.
Reach for a Fragment when the reusable chunk is small, tightly tied to the logic of one parent page, and only ever swapped in and out within that same parent's own template — a classic example is toggling between a "view mode" and "edit mode" rendering of one row in a table, where both variants live conveniently in the same parent HTML file.
Reach for a Panel once the component needs to appear across multiple, unrelated pages, has grown complex enough to deserve its own dedicated Java class and HTML file, or would make the parent's markup cluttered if kept inline. A "user profile card" that shows up in a dashboard, a settings page, and a public profile view is a clear Panel candidate, since duplicating that markup as separate Fragments in three different parent templates would violate the same reuse goal Panels exist to solve.
More Related questions...