Markup inheritance is often more convenient to use than Borders; be sure to learn about markup inheritance as well.
This page needs an update
The provided solution doesn't work with either wicket 1.2.x nor 1.3.x, as MarkupContainer#add(Component) is final and can't be overriden.
See this thread on the mailing list.
Creating consistent page layouts using Borders
Borders are one of the most powerful components provided with the Wicket framework. However, this also makes them the most difficult to explain and understand. This short article covers how to use the Border component to create a standard site template that wraps around all of the pages in your site to ensure that they are consistent and to reduce the duplication of common HTML code (such as including menu areas and so on).
To build a site based on a standard border template we need to create three files. The first file is the Java file for the border:
We then need to create the HTML markup file:
One important thing to note about this is that I have written the HTML markup for the file so that it only represents the BODY part of the common page. It is possible to include the HEAD part of a common page in the markup, but I don't do this for a couple of reasons:
The next stage is to create a Page base class that all pages must extend. This is worth doing as it then forces use of the border and minimises the amount of code required:
Finally, everything is set up and I am now ready to create real pages for my site. First I need a the Java code for a page:
Then I just need the HTML to go with the page:
To merge the HEAD part of both HTM files, e.g. to specify a common css for all files but give each page a unique title, modify the above example like this:
The border's markup:
and the page markup:
Note: If the body element is not an immediate child of border (example see below), than you must use someContainer.add(getBodyContainer()) to add the body component to the correct container.
Note: contributions to <wicket:head>
Note which tags are contributed to the final page output.
In a border or in a panel, anything outside <wicket:border>..</wicket:border> and <wicket:panel>...</wicket:panel> tags will be ignored, the exception being the body of the <wicket:head> tag.
At the page level, as pages are "top level" components, they don't need special <wicket:page> tags and the like. Therefore in pages, nothing is ignored unless you explicitly tell Wicket to do so by using <wicket:remove> tags.