Contributing to the page head
The output of a Wicket html page is composed by assembling various things (borders, panels, page extensions, and of course pages themselves). Anything in a "normal" page is automatically contributed to the output. The same cannot be said, however, for borders, panels, or page extensions.
These components (identified respectively by <wicket:border, wicket:panel>, and <wicket:extend> tags) allow the use of a <head> section, but by default, the head is only for previewing. In other words, anything you add to the <head> in one of these types of components will NOT be contributed to the final page output unless you explicitly add it yourself.
In general terms, when you create a panel and want to contribute something to the page head, you would use this type of structure:
So, assuming that your page output looks something like this:
The output generated, including the contribution to head made by the panel above, will look something like:
Using <wicket:head> to contribute CSS
If we are able to use the <wicket:head> section above to contribute to the page model, then we can certainly use it to reference a CSS resource!
First, the html:
And now, the java:
Customizing CSS output based on some parameters
You can customize CSS output based on various parameters, such as local, browser agent, etc. The easiest way is to use an anonymous class as follows.
In your html:
In your java:
A word of caution about the <body> tag
There is one more thing to mention. The onLoad attribute of <body> is sometimes used to initialize certain functionality. E.g.
Linking directly to a CSS page
To the CSS file(s), insert something like this in your markup:
and this in your Page Java file for Wicket 1.1:
or this for Wicket 1.2: