Including CSS and JS Files in Wicket Applications

I am the first timer with a Wicket card and have tried it for an internal project in my company. We have our own CSS files for themes and a JavaScript library built on Dojo for creating widgets.

I have two questions about including these external resources:

  • Where should these resource folders be located? Do they go directly below the application or should they be placed in the Java package folder along with the HTML files?

  • Will there be a standard way to bind CSS and JS in the <head> section?

My project uses Wicket 1.5.

+4
source share
1 answer

As jbrookover pointed out, there used to be two ways to enable CSS and JS. One of them is to use the <wicket:head> tags, for example:

 <wicket:head> <wicket:link> <link href="yourStylesheet.css" rel="stylesheet" type="text/css" /> </wicket:link> </wicket:head> 

The second way was to include header contributors, for example:

 // From v1.3; deprecated in v1.4 and removed in v1.5 add(HeaderContributor.forJavaScript(Foo.class, "yourScripts.js")); 

or

 // From v1.4; removed in v1.5 JavascriptPackageResource.getHeaderContribution(Foo.class, "yourScripts.js") 

Actually there was a third, more complex way, which included writing a custom header contributor and the renderHead() method. Since you are using version 1.5, the second method is not available, and you will need to select the <wicket:head> tags or a slightly modified version of the complex method. See the Wicket wiki “Migrating to a Wicket 1.5 Page”; in particular, the three sections that begin here .

+4
source

All Articles