0

I am a little confused about tags. I know from wicket 1.5 there was a change of head render strategy from parent->child to child->parent.

Now I use wicket 6.9 and I have simple menu panel which I want to use some jquery effects. I want to use the same jquery (for example for google) file for whole application.

I cannot use jquery link only in main page, because in while rendering menu panel there is " $(document).ready" and it is not recognized. Reading some forum i found opinion that panel should contain jquery itselft - it is reasonable, because it can be reusable independently.

So now my page consist:

<head>
  ...
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
  ...
</head>

And my menu panel consist the same. As a result in rendered html I load jquery.js twice.

How should I resolve it? I want to load it only once. I know i can back to old strategy and do application.getResourcesSettings().setHeaderItemComparator() but as i read it is not the best solution.

I can found such class like PriorityHeaderItem in wicket, but documentation is very poor for wicket and did not found any example of use it.

Best regards

Michał Króliczek
  • 1,319
  • 1
  • 11
  • 16

1 Answers1

0

Since wicket 1.6 jQuery is now the javascript library used by the framework. So you may see jQuery twice because of the one you included and the wicket version? If you want to override the jQuery version you can create a Resource Reference and then set it in your init method of the Application class.

First you need the resource reference file and put the js file in same package structure.

public final class JQueryResourceReference extends JavaScriptResourceReference {

    private static final JQueryResourceReference INSTANCE = new JQueryResourceReference();

    private JQueryResourceReference() {
        super(JQueryResourceReference.class, "jquery.js");
    }

    public static JQueryResourceReference get() {
        return INSTANCE;
    }
}

Then in the application init method do this:

public MyApplication extends AuthenticatedWebApplication {

    @Override
    protected void init() {
        super.init();

        getJavaScriptLibrarySettings().setJQueryReference(JQueryResourceReference.get());

         ....
     }

     ....
}
ZeusSelerim
  • 935
  • 8
  • 12