You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by gs...@apache.org on 2007/12/03 00:08:28 UTC

svn commit: r600406 - in /wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java

Author: gseitz
Date: Sun Dec  2 15:08:27 2007
New Revision: 600406

URL: http://svn.apache.org/viewvc?rev=600406&view=rev
Log:
WICKET-745: AbstractAjaxTimerBehaviors can again be added via ajax

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java?rev=600406&r1=600405&r2=600406&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java Sun Dec  2 15:08:27 2007
@@ -42,6 +42,8 @@
 
 	private boolean stopped = false;
 
+	private boolean headRendered = false;
+
 	/**
 	 * Construct.
 	 * 
@@ -99,8 +101,9 @@
 
 		WebRequest request = (WebRequest)RequestCycle.get().getRequest();
 
-		if (!stopped && request.isAjax() == false)
+		if (!stopped && !headRendered)
 		{
+			headRendered = true;
 			response.renderOnLoadJavascript(getJsTimeoutCall(updateInterval));
 		}
 	}
@@ -114,13 +117,13 @@
 	{
 		// this might look strange, but it is necessary for IE not to leak :(
 		return "setTimeout(\"" + getCallbackScript() + "\", " + updateInterval.getMilliseconds() +
-				");";
+			");";
 	}
 
 	protected CharSequence getCallbackScript()
 	{
 		return generateCallbackScript("wicketAjaxGet('" + getCallbackUrl(onlyTargetActivePage()) +
-				"'");
+			"'");
 	}
 
 	/**
@@ -133,7 +136,7 @@
 		{
 			String componentId = getComponent().getMarkupId();
 			precondition = "var c = Wicket.$('" + componentId +
-					"'); return typeof(c) != 'undefined' && c != null";
+				"'); return typeof(c) != 'undefined' && c != null";
 		}
 		return precondition;
 	}

Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java?rev=600406&r1=600405&r2=600406&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java Sun Dec  2 15:08:27 2007
@@ -63,8 +63,7 @@
 		final MyAjaxSelfUpdatingTimerBehavior timer = new MyAjaxSelfUpdatingTimerBehavior(dur);
 		final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
 
-		page.add(new WebComponent(MockPageWithLinkAndComponent.COMPONENT_ID)
-				.setOutputMarkupId(true));
+		page.add(new WebComponent(MockPageWithLinkAndComponent.COMPONENT_ID).setOutputMarkupId(true));
 
 
 		page.add(new AjaxLink(MockPageWithLinkAndComponent.LINK_ID)
@@ -74,7 +73,7 @@
 			public void onClick(AjaxRequestTarget target)
 			{
 				WebMarkupContainer wmc = new WebMarkupContainer(
-						MockPageWithLinkAndComponent.COMPONENT_ID);
+					MockPageWithLinkAndComponent.COMPONENT_ID);
 				wmc.setOutputMarkupId(true);
 				wmc.add(timer);
 				page.replace(wmc);
@@ -137,11 +136,11 @@
 		String document = tester.getServletResponse().getDocument();
 
 		String updateScript = timer.getUpdateScript();
-		String bodyOnLoadUpdateScript = "Wicket.Event.add(window, \"load\", function() { " +
-				updateScript + ";});";
 
 		if (inBodyOnLoad)
 		{
+			String bodyOnLoadUpdateScript = "Wicket.Event.add(window, \"load\", function() { " +
+				updateScript + ";});";
 			validateTimerScript(document, bodyOnLoadUpdateScript);
 		}
 		else
@@ -152,6 +151,12 @@
 
 		tester.executeBehavior(timer);
 
+
+		if (inBodyOnLoad)
+		{
+			updateScript = timer.getUpdateScript();
+		}
+
 		// Validate the document
 		document = tester.getServletResponse().getDocument();
 		validateTimerScript(document, updateScript);
@@ -180,7 +185,7 @@
 		}
 		// make sure there is only one match
 		assertEquals("There should be 1 and only 1 script in the markup for this behavior," +
-				"but " + count + " were found", 1, count);
+			"but " + count + " were found", 1, count);
 	}
 
 	// quick fix for JDK 5 method
@@ -225,7 +230,7 @@
 		public MyAjaxSelfUpdatingTimerBehavior(Duration updateInterval)
 		{
 			super(updateInterval);
-			this.duration = updateInterval;
+			duration = updateInterval;
 		}
 
 		protected void onComponentRendered()