Author: ivaynberg
Date: Sat Aug 7 00:45:56 2010
New Revision: 983152
URL: http://svn.apache.org/viewvc?rev=983152&view=rev
Log:
WICKET-2969 illegal state if super.oninitialize is missing
Issue: WICKET-2969
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/MarkupContainer.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.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=983152&r1=983151&r2=983152&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
Sat Aug 7 00:45:56 2010
@@ -635,10 +635,12 @@ public abstract class Component implemen
/** True when a component has been initialized, had {...@link
#onInitialize()} called */
protected static final int FLAG_INITIALIZED = 0x400000;
+
/** True when component has been configured, had {...@link
#onConfigure()} called */
protected static final int FLAG_CONFIGURED = 0x800000;
- private static final int FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED =
0x1000000;
+ private static final int FLAG_INITIALIZE_SUPER_CALL_VERIFIED =
0x10000000;
+ private static final int FLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED =
0x1000000;
/**
* Flag that makes we are in before-render callback phase Set after
component.onBeforeRender is
@@ -928,8 +930,8 @@ public abstract class Component implemen
final IDebugSettings debugSettings =
Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnNewComponentEnabled())
{
- setMetaData(CONSTRUCTED_AT_KEY, Strings.toString(this,
new MarkupException(
- "constructed")));
+ setMetaData(CONSTRUCTED_AT_KEY,
+ Strings.toString(this, new
MarkupException("constructed")));
}
if (model != null)
@@ -1058,7 +1060,7 @@ public abstract class Component implemen
if ((determineVisibility() || callOnBeforeRenderIfNotVisible())
&&
!getFlag(FLAG_RENDERING) &&
!getFlag(FLAG_PREPARED_FOR_RENDER))
{
- setFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED,
false);
+ setFlag(FLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED, false);
getApplication().notifyPreComponentOnBeforeRenderListeners(this);
@@ -1069,7 +1071,7 @@ public abstract class Component implemen
onBeforeRender();
getApplication().notifyPostComponentOnBeforeRenderListeners(this);
- if (!getFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED))
+ if (!getFlag(FLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED))
{
throw new
IllegalStateException(Component.class.getName() +
" has not been properly rendered.
Something in the hierarchy of " +
@@ -3291,9 +3293,13 @@ public abstract class Component implemen
final Page page = findPage();
if (page == null)
{
- return new StringBuffer("[Component id =
").append(getId()).append(
- ", page = <No Page>, path =
").append(getPath()).append(".").append(
-
Classes.simpleName(getClass())).append("]").toString();
+ return new StringBuffer("[Component id =
").append(getId())
+ .append(", page = <No Page>, path = ")
+ .append(getPath())
+ .append(".")
+ .append(Classes.simpleName(getClass()))
+ .append("]")
+ .toString();
}
else
{
@@ -3923,7 +3929,7 @@ public abstract class Component implemen
{
setFlag(FLAG_PREPARED_FOR_RENDER, true);
onBeforeRenderChildren();
- setFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED, true);
+ setFlag(FLAG_BEFORE_RENDER_SUPER_CALL_VERIFIED, true);
}
/**
@@ -4009,23 +4015,32 @@ public abstract class Component implemen
}
/**
- * Calls {...@link #doInitialize()}, is overridden by {...@link
MarkupContainer} to create an
+ * Calls {...@link #fireInitialize()}, is overridden by {...@link
MarkupContainer} to create an
* {...@link IVisitor} to walk over the child hierarchy.
*/
void initialize()
{
- doInitialize();
+ fireInitialize();
}
/**
* Used to call {...@link #onInitialize()}
*/
- final void doInitialize()
+ final void fireInitialize()
{
if (!getFlag(FLAG_INITIALIZED))
{
setFlag(FLAG_INITIALIZED, true);
+ setFlag(FLAG_INITIALIZE_SUPER_CALL_VERIFIED, false);
onInitialize();
+ if (!getFlag(FLAG_INITIALIZE_SUPER_CALL_VERIFIED))
+ {
+ throw new
IllegalStateException(Component.class.getName() +
+ " has not been properly initialized.
Something in the hierarchy of " +
+ getClass().getName() +
+ " has not called super.onInitializer()
in the override of onInitialize() method");
+ }
+ setFlag(FLAG_INITIALIZE_SUPER_CALL_VERIFIED, false);
}
}
@@ -4118,6 +4133,7 @@ public abstract class Component implemen
*/
protected void onInitialize()
{
+ setFlag(FLAG_INITIALIZE_SUPER_CALL_VERIFIED, true);
}
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=983152&r1=983151&r2=983152&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Sat Aug 7 00:45:56 2010
@@ -402,20 +402,20 @@ public abstract class MarkupContainer ex
}
/**
- * Overrides {...@link Component#initialize()} to call {...@link
Component#doInitialize()} for itself
+ * Overrides {...@link Component#initialize()} to call {...@link
Component#fireInitialize()} for itself
* and for all its children.
*
- * @see org.apache.wicket.Component#doInitialize()
+ * @see org.apache.wicket.Component#fireInitialize()
*/
@Override
final void initialize()
{
- super.doInitialize();
+ super.fireInitialize();
visitChildren(new IVisitor<Component>()
{
public Object component(Component component)
{
- component.doInitialize();
+ component.fireInitialize();
return CONTINUE_TRAVERSAL;
}
});
Modified:
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java?rev=983152&r1=983151&r2=983152&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
Sat Aug 7 00:45:56 2010
@@ -17,6 +17,7 @@
package org.apache.wicket;
import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
@@ -110,6 +111,21 @@ public class ComponentInitializationTest
assertEquals(1, page.getCount());
}
+ public void testErrorInDevelopedComponents()
+ {
+ TestPage page = new TestPage();
+ boolean illegalState = false;
+ try
+ {
+ page.add(new
PossibleDevelopedComponent("addedComponent"));
+ }
+ catch (IllegalStateException e)
+ {
+ illegalState = true;
+ }
+ assertTrue(illegalState);
+ }
+
public static class TestPage extends WebPage implements
IMarkupResourceStreamProvider
{
private int count = 0;
@@ -121,6 +137,7 @@ public class ComponentInitializationTest
@Override
protected void onInitialize()
{
+ super.onInitialize();
count++;
add(new Label("addedComponent",
"Testing addition of a component to show
StackOverflowError"));
@@ -151,6 +168,7 @@ public class ComponentInitializationTest
@Override
protected void onInitialize()
{
+ super.onInitialize();
count++;
}
@@ -161,4 +179,30 @@ public class ComponentInitializationTest
}
+
+ private static class PossibleDevelopedComponent extends WebComponent
+ {
+ private final boolean initialized = false;
+
+ public PossibleDevelopedComponent(String id)
+ {
+ super(id);
+ }
+
+ @Override
+ protected void onBeforeRender()
+ {
+ super.onBeforeRender();
+ if (!initialized)
+ {
+ onInitialize();
+ }
+ }
+
+ @Override
+ protected void onInitialize()
+ {
+ // possible already implemented method by some user
+ }
+ }
}