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:16:47 UTC
svn commit: r1094684 - in /wicket/trunk/wicket-core/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:16:46 2011
New Revision: 1094684
URL: http://svn.apache.org/viewvc?rev=1094684&view=rev
Log:
WICKET-3563 Interaction betwen IAjaxRegionMarkupIdProvider, renderPlaceholderTag and visibility
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java?rev=1094684&r1=1094683&r2=1094684&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java Mon Apr 18 18:16:46 2011
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Stack;
+import org.apache.wicket.ajax.IAjaxRegionMarkupIdProvider;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.AuthorizationException;
import org.apache.wicket.authorization.IAuthorizationStrategy;
@@ -2463,7 +2464,7 @@ public abstract class Component
}
response.write(tag.getName());
response.write(" id=\"");
- response.write(getMarkupId());
+ response.write(getAjaxRegionMarkupId());
response.write("\" style=\"display:none\"></");
if (ns != null)
{
@@ -2473,6 +2474,39 @@ public abstract class Component
response.write(">");
}
+
+ /**
+ * 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 (Behavior 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;
+ }
+
+
/**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.
* <p>
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=1094684&r1=1094683&r2=1094684&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java Mon Apr 18 18:16:46 2011
@@ -31,7 +31,6 @@ import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.Page;
-import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.event.Broadcast;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.internal.HeaderResponse;
@@ -753,7 +752,7 @@ public class AjaxRequestTarget implement
if (!containsAncestorFor(component))
{
- respondComponent(response, getAjaxRegionMarkupId(component), component);
+ respondComponent(response, component.getAjaxRegionMarkupId(), component);
}
}
@@ -803,30 +802,6 @@ public class AjaxRequestTarget implement
}
}
- private String getAjaxRegionMarkupId(Component component)
- {
- String markupId = null;
- for (Behavior 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/trunk/wicket-core/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java?rev=1094684&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/PlaceholderTagIdTest.java Mon Apr 18 18:16:46 2011
@@ -0,0 +1,90 @@
+/*
+ * 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.Behavior;
+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 Behavior implements IAjaxRegionMarkupIdProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ public String getAjaxRegionMarkupId(Component component)
+ {
+ return component.getMarkupId() + "_region";
+ }
+
+ }
+}