(no commit message)
authorErik Brakkee <erik@brakkee.org>
Fri, 27 Aug 2010 22:37:30 +0000 (22:37 +0000)
committerErik Brakkee <erik@brakkee.org>
Fri, 27 Aug 2010 22:37:30 +0000 (22:37 +0000)
wicket/components/src/main/java/org/wamblee/wicket/jquery/JQueryBehavior.java

index fb142ba66eaab5e0c0f1bbbfec6986f38dae260f..0efab6fabdfde8a926776877acf8b20887e071f1 100644 (file)
@@ -18,7 +18,6 @@ package org.wamblee.wicket.jquery;
 import org.apache.wicket.Application;
 import org.apache.wicket.behavior.HeaderContributor;
 import org.apache.wicket.markup.html.JavascriptPackageResource;
-import org.apache.wicket.markup.html.resources.JavascriptResourceReference;
 
 /**
  * JQuery bahavior which adds the jquery javascript.
@@ -30,16 +29,28 @@ public class JQueryBehavior extends HeaderContributor {
     static final String JQUERY_DEPLOYMENT = "jquery-1.4.2.min.js";
     static final String JQUERY_DEVELOPMENT = "jquery-1.4.2.js";
 
+    private static HeaderContributor CACHE;
+
     /**
      * Constructs the behavior.
      */
     public JQueryBehavior() {
-        super(initializeInstance());
+        super(getContributor());
     }
     
-    private static HeaderContributor initializeInstance() {
-        return JavascriptPackageResource.getHeaderContribution(
-            JQueryBehavior.class, getJQueryJavascript());
+    /**
+     * Resets the cached value of the header contribution. Used typically for test only.
+     */
+    public static void clear() { 
+        CACHE = null; 
+    }
+
+    private static HeaderContributor getContributor() {
+        if (CACHE == null) {
+            CACHE = JavascriptPackageResource.getHeaderContribution(
+                JQueryBehavior.class, getJQueryJavascript());
+        }
+        return CACHE;
     }
 
     private static String getJQueryJavascript() {