From 0e68c3016f4a5c40c7d16b9a69c52721f9cc7a43 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Fri, 27 Aug 2010 22:37:30 +0000 Subject: [PATCH] --- .../wamblee/wicket/jquery/JQueryBehavior.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/wicket/components/src/main/java/org/wamblee/wicket/jquery/JQueryBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/jquery/JQueryBehavior.java index fb142ba6..0efab6fa 100644 --- a/wicket/components/src/main/java/org/wamblee/wicket/jquery/JQueryBehavior.java +++ b/wicket/components/src/main/java/org/wamblee/wicket/jquery/JQueryBehavior.java @@ -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() { -- 2.31.1