You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2011/04/18 20:15:42 UTC

svn commit: r1094682 - in /wicket/branches/wicket-1.4.x/wicket/src: main/java/org/apache/wicket/Component.java main/java/org/apache/wicket/ajax/AjaxRequestTarget.java test/java/org/apache/wicket/PlaceholderTagIdTest.java

Author: mgrigorov
Date: Mon Apr 18 18:15:41 2011
New Revision: 1094682

URL: http://svn.apache.org/viewvc?rev=1094682&view=rev
Log:
WICKET-3563 Interaction betwen IAjaxRegionMarkupIdProvider, renderPlaceholderTag and visibility--This line, and those below, will be ignored--

A    src/test/java/org/apache/wicket/PlaceholderTagIdTest.java
M    src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
M    src/main/java/org/apache/wicket/Component.java

Added:
    wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java
Modified:
    wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
    wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java

Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java?rev=1094682&r1=1094681&r2=1094682&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java Mon Apr 18 18:15:41 2011
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Locale;
 
 import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.IAjaxRegionMarkupIdProvider;
 import org.apache.wicket.authorization.Action;
 import org.apache.wicket.authorization.AuthorizationException;
 import org.apache.wicket.authorization.IAuthorizationStrategy;
@@ -2587,7 +2588,7 @@ public abstract class Component implemen
 		}
 		response.write(tag.getName());
 		response.write(" id=\"");
-		response.write(getMarkupId());
+		response.write(getAjaxRegionMarkupId());
 		response.write("\" style=\"display:none\"></");
 		if (ns != null)
 		{
@@ -2598,6 +2599,37 @@ public abstract class Component implemen
 	}
 
 	/**
+	 * Returns the id of the markup region that will be updated via ajax. This can be different to
+	 * the markup id of the component if a {@link IAjaxRegionMarkupIdProvider} behavior has been
+	 * added.
+	 * 
+	 * @return the markup id of the region to be updated via ajax.
+	 */
+	public final String getAjaxRegionMarkupId()
+	{
+		String markupId = null;
+		for (IBehavior behavior : getBehaviors())
+		{
+			if (behavior instanceof IAjaxRegionMarkupIdProvider)
+			{
+				markupId = ((IAjaxRegionMarkupIdProvider)behavior).getAjaxRegionMarkupId(this);
+			}
+		}
+		if (markupId == null)
+		{
+			if (this instanceof IAjaxRegionMarkupIdProvider)
+			{
+				markupId = ((IAjaxRegionMarkupIdProvider)this).getAjaxRegionMarkupId(this);
+			}
+		}
+		if (markupId == null)
+		{
+			markupId = getMarkupId();
+		}
+		return markupId;
+	}
+
+	/**
 	 * Page.renderPage() is used to render a whole page. With AJAX however it must be possible to
 	 * render any one component contained in a page. That is what this method is for.
 	 * <p>

Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=1094682&r1=1094681&r2=1094682&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java Mon Apr 18 18:15:41 2011
@@ -36,7 +36,6 @@ import org.apache.wicket.Page;
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.ResourceReference;
 import org.apache.wicket.Response;
-import org.apache.wicket.behavior.IBehavior;
 import org.apache.wicket.markup.html.IHeaderResponse;
 import org.apache.wicket.markup.html.internal.HeaderResponse;
 import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
@@ -678,7 +677,7 @@ public class AjaxRequestTarget implement
 
 			if (!containsAncestorFor(component))
 			{
-				respondComponent(response, getAjaxRegionMarkupId(component), component);
+				respondComponent(response, component.getAjaxRegionMarkupId(), component);
 			}
 		}
 
@@ -732,30 +731,6 @@ public class AjaxRequestTarget implement
 		}
 	}
 
-	private String getAjaxRegionMarkupId(Component component)
-	{
-		String markupId = null;
-		for (IBehavior behavior : component.getBehaviors())
-		{
-			if (behavior instanceof IAjaxRegionMarkupIdProvider)
-			{
-				markupId = ((IAjaxRegionMarkupIdProvider)behavior).getAjaxRegionMarkupId(component);
-			}
-		}
-		if (markupId == null)
-		{
-			if (component instanceof IAjaxRegionMarkupIdProvider)
-			{
-				markupId = ((IAjaxRegionMarkupIdProvider)component).getAjaxRegionMarkupId(component);
-			}
-		}
-		if (markupId == null)
-		{
-			markupId = component.getMarkupId();
-		}
-		return markupId;
-	}
-
 	/**
 	 * Checks if the target contains an ancestor for the given component
 	 * 

Added: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java?rev=1094682&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java Mon Apr 18 18:15:41 2011
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket;
+
+import org.apache.wicket.ajax.IAjaxRegionMarkupIdProvider;
+import org.apache.wicket.behavior.AbstractBehavior;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Test;
+
+/**
+ * Test for <a href="https://issues.apache.org/jira/browse/WICKET-3563">WICKET-3563</a>
+ */
+public class PlaceholderTagIdTest
+{
+
+	/**
+	 * If a component either implements {@link IAjaxRegionMarkupIdProvider} or has a behavior which
+	 * implements it then the placeholder markup id for it should be the one defined by the
+	 * {@link IAjaxRegionMarkupIdProvider}
+	 */
+	@Test
+	public void wicket3563()
+	{
+		WicketTester tester = new WicketTester();
+		tester.startPage(TestPage.class);
+
+		tester.assertContains("<form id=\"form1_region\" style=\"display:none\">");
+	}
+
+	/**
+	 *
+	 */
+	public static class TestPage extends WebPage implements IMarkupResourceStreamProvider
+	{
+		private static final long serialVersionUID = 1L;
+
+		/**
+		 * Construct.
+		 */
+		public TestPage()
+		{
+			Form<?> form = new Form<Void>("form");
+			form.setVisible(false);
+			form.setOutputMarkupPlaceholderTag(true);
+			add(form);
+
+			form.add(new RegionBehavior());
+		}
+
+		public IResourceStream getMarkupResourceStream(MarkupContainer container,
+			Class<?> containerClass)
+		{
+			return new StringResourceStream(
+				"<html><body><form wicket:id='form'></form></body></html>");
+		}
+	}
+
+	/**
+	 * A behavior that implements {@link IAjaxRegionMarkupIdProvider}
+	 */
+	public static class RegionBehavior extends AbstractBehavior
+		implements
+			IAjaxRegionMarkupIdProvider
+	{
+		private static final long serialVersionUID = 1L;
+
+		public String getAjaxRegionMarkupId(Component component)
+		{
+			return component.getMarkupId() + "_region";
+		}
+
+	}
+}