1

I want to have something like the following.

<head>
   <% if deployment == true %>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
   <% else %>
   <script src="js/lib/ref/jquery-1.6.2.js"></script>
   <% endif %>       
</head>

How can I do this in wicket?

Update:

Sorry, I was simplifying. Actually I want to include this just before the close body tag.

Alistair
  • 1,939
  • 2
  • 22
  • 31

1 Answers1

3

You can make your WebPage class implement the IHeaderContributer interface.

Then your class can override the following method

public void renderHeader(IHeaderResponse response) {
    if (deployment) {
        response.renderJavascriptReference("https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js");
    }
    else {
        response.renderJavascriptReference("js/lib/ref/jquery-1.6.2.js");
    }
Andrew Fielden
  • 3,751
  • 3
  • 31
  • 47
  • 1
    FYI, the appropriate method is `Application.get().getConfigurationType();` – jbrookover Jul 27 '11 at 15:33
  • Hmm, ok I was simplifying. Actually these will go just before the end of the body. I assume this will change the method I need to use? – Alistair Jul 28 '11 at 06:14
  • Thanks jbrookover. @Alistair: Is there a problem putting these script definitions in the head section? That's really where they should be placed. – Andrew Fielden Jul 28 '11 at 08:40
  • Best practice is to include external script files just before the close body tag. http://stackoverflow.com/questions/143486/unobtrusive-javascript-script-at-the-top-or-the-bottom-of-the-html-code . Basically in some older browsers this is the difference between users getting something to look at while your JS is loading as opposed to a blank screen. I think there are some performance benefits as well. – Alistair Jul 28 '11 at 22:46
  • 1
    @Alistair you can use a wicket:id on a script tag, add a `WebmarkupContainer` and then modify the `src` attribute, via `onComponentTag` or an `AttributeModifier` based on the Application configuration. – jbrookover Aug 03 '11 at 15:31