add re_added flag
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/055958a9 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/055958a9 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/055958a9 Branch: refs/heads/WICKET-5677 Commit: 055958a9c60db45d96c1828803dbee37e5926678 Parents: 348e9db Author: Carl-Eric Menzel <[email protected]> Authored: Mon Aug 25 07:23:57 2014 +0200 Committer: Carl-Eric Menzel <[email protected]> Committed: Mon Aug 25 07:23:57 2014 +0200 ---------------------------------------------------------------------- .../main/java/org/apache/wicket/Component.java | 24 +++++++++++++------- .../java/org/apache/wicket/OnReAddTest.java | 10 ++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/055958a9/wicket-core/src/main/java/org/apache/wicket/Component.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java index 0f91095..543c087 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Component.java +++ b/wicket-core/src/main/java/org/apache/wicket/Component.java @@ -411,6 +411,8 @@ public abstract class Component private static final int FLAG_VISIBILITY_ALLOWED = 0x40000000; private static final int FLAG_DETACHING = 0x80000000; + + private static final int FLAG_RE_ADDED = 0x400000; /** * The name of attribute that will hold markup id @@ -888,14 +890,18 @@ public abstract class Component } else { - setRequestFlag(RFLAG_ON_RE_ADD_SUPER_CALL_VERIFIED, false); - onReAdd(); - if (!getRequestFlag(RFLAG_ON_RE_ADD_SUPER_CALL_VERIFIED)) + if (!getFlag(FLAG_RE_ADDED)) { - throw new IllegalStateException(Component.class.getName() + - " has not been properly added. Something in the hierarchy of " + - getClass().getName() + - " has not called super.onReAdd() in the override of onReAdd() method"); + setFlag(FLAG_RE_ADDED, true); + setRequestFlag(RFLAG_ON_RE_ADD_SUPER_CALL_VERIFIED, false); + onReAdd(); + if (!getRequestFlag(RFLAG_ON_RE_ADD_SUPER_CALL_VERIFIED)) + { + throw new IllegalStateException(Component.class.getName() + + " has not been properly added. Something in the hierarchy of " + + getClass().getName() + + " has not called super.onReAdd() in the override of onReAdd() method"); + } } } } @@ -1136,6 +1142,7 @@ public abstract class Component { setFlag(FLAG_REMOVING_FROM_HIERARCHY, true); onRemove(); + setFlag(FLAG_RE_ADDED, false); if (getFlag(FLAG_REMOVING_FROM_HIERARCHY)) { throw new IllegalStateException(Component.class.getName() + @@ -4508,7 +4515,8 @@ public abstract class Component * then * added again: * - * <ul><li>onInitialize is only called the very first time a component is added</li> + * <ul> + * <li>onInitialize is only called the very first time a component is added</li> * <li>onReAdd is not called the first time, but every time it is re-added after having been * removed</li> * </ul> http://git-wip-us.apache.org/repos/asf/wicket/blob/055958a9/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java b/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java index fb9535b..8d552e0 100644 --- a/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/OnReAddTest.java @@ -89,6 +89,16 @@ public class OnReAddTest page.add(probe); assertTrue(onReAddCalled); assertFalse(onInitializeCalled); + onReAddCalled = false; + page.internalInitialize(); + // just another initialize run shouldn't call onReAdd nor onInitialize. onReAdd should only be called + // after remove and add + assertFalse(onReAddCalled); + assertFalse(onInitializeCalled); + page.remove(probe); + page.add(probe); + assertTrue(onReAddCalled); + assertFalse(onInitializeCalled); } @Test
