Author: ivaynberg
Date: Sat Feb 19 19:55:44 2011
New Revision: 1072428
URL: http://svn.apache.org/viewvc?rev=1072428&view=rev
Log:
Issue: WICKET-3455
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java
(with props)
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java?rev=1072428&r1=1072427&r2=1072428&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
Sat Feb 19 19:55:44 2011
@@ -631,6 +631,7 @@ public abstract class MarkupContainer ex
// Do not call remove() because the
state change would than be
// recorded twice.
+ child.internalOnRemove();
child.detachModel();
child.setParent(null);
}
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java?rev=1072428&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java
(added)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java
Sat Feb 19 19:55:44 2011
@@ -0,0 +1,159 @@
+/*
+ * 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.markup;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+
+/**
+ * Tests child's {@link Component#onRemove} is on refresh
+ *
+ * @author igor
+ */
+public class RefreshingViewOnRemoveTest extends WicketTestCase
+{
+ private final List<TestComponent> components = new
ArrayList<TestComponent>();
+ private int round = 1;
+
+ public void test()
+ {
+ tester.startPage(new TestPage());
+
+ // check everything was detached
+ for (TestComponent c : components)
+ {
+ assertTrue(c.detached);
+ }
+
+ round++;
+ tester.startPage(tester.getLastRenderedPage());
+
+ // check everything was detached
+ for (TestComponent c : components)
+ {
+ assertTrue(c.detached);
+ }
+
+ // check we have round 1 and round 2 components
+ boolean round1 = false;
+ boolean round2 = false;
+ for (TestComponent c : components)
+ {
+ if (c.round == 1)
+ round1 = true;
+ if (c.round == 2)
+ round2 = true;
+ }
+ assertTrue(round1);
+ assertTrue(round2);
+
+ // check onremove was called on all round 1 components
+ for (TestComponent c : components)
+ {
+ if (c.round == 1)
+ assertTrue(c.removed);
+ }
+
+ }
+
+ protected Component newComponent(String id)
+ {
+ TestComponent c = new TestComponent(id, round);
+ components.add(c);
+ return c;
+ }
+
+ public static class TestComponent extends Label
+ {
+
+ public boolean detached = false;
+ public boolean removed = false;
+ public final int round;
+
+ public TestComponent(String id, int round)
+ {
+ super(id, id);
+ this.round = round;
+ }
+
+ @Override
+ protected void onDetach()
+ {
+ super.onDetach();
+ detached = true;
+ }
+
+ @Override
+ protected void onRemove()
+ {
+ super.onRemove();
+ removed = true;
+ }
+ }
+
+ public class TestPage extends WebPage implements
IMarkupResourceStreamProvider
+ {
+ public TestPage()
+ {
+ add(new RefreshingView<Integer>("repeater")
+ {
+ @Override
+ protected Iterator<IModel<Integer>>
getItemModels()
+ {
+ return new
ModelIteratorAdapter<Integer>(Arrays.asList(new Integer[] { 1, 2 })
+ .iterator())
+ {
+ @Override
+ protected IModel<Integer>
model(Integer object)
+ {
+ return Model.of(object);
+ }
+ };
+ }
+
+ @Override
+ protected void populateItem(Item<Integer> item)
+ {
+ item.add(newComponent("label"));
+ }
+ });
+ }
+
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer
container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream(
+ "<html><body><ul><li wicket:id='repeater'><span
wicket:id='label'></span></li></ul></body></html>");
+ }
+ }
+}
Propchange:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/RefreshingViewOnRemoveTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain