Wicket 1.3 and earlier
To add A quick howto on adding Javascript or CSS to your pages , and having have them compressed during the "deployment" cycle automatically by Wicket. So to , start with , we need to copy or the Javascript or CSS file somewhere in our package hierarchy that we can reference in our Page. For simplicity, we can copy it right next to the HTML file like so:
...
Code Block |
---|
add(HeaderContributor.forJavaScript( MYPAGE_JS )); add(HeaderContributor.forCss( MYPAGE_CSS )); |
Wicket 1.4
In Wicket 1.4 HeaderContributor.forJavaScript() and HeaderContributor.forCss() is are deprecated, you can use thisso use the code below:
Code Block |
---|
add(JavascriptPackageResource.getHeaderContribution(BASEPAGEMYPAGE_JS)); add(JavascriptPackageResourceCSSPackageResource.getHeaderContribution(MYPAGE_CSS)); |
Or
Code Block |
---|
public class MyPage extends WebPage { ... @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); response.renderJavascriptReference(new JavascriptResourceReference(MyPage.class, "script.js")); } ... |
Also see the example for Wicket 1.5.
Wicket 1.5
In Wicket 1.5, CompressedResourceReference has been removed!
Also, the getHeaderContribution
functionality has been removed. Instead, your component (Page, Panel, etc.) needs to override renderHead(IHeaderResponse):
Code Block |
---|
public class MyPage extends WebPage implements IHeaderContributor {
...
@Override
public void renderHead(IHeaderResponse response) {
response.renderJavaScriptReference("urlHere");
}
|
Wicket 6.x
renderJavaScriptReference
seems to be gone.
Code Block |
---|
...
private static final JavaScriptResourceReference MYPAGE_JS = new JavaScriptResourceReference(MyPage.class, "MyPage.js");
...
@Override
public void renderHead(IHeaderResponse response) {
response.render(JavaScriptReferenceHeaderItem.forReference(MYPAGE_JS));
}
...
|