Author: ivaynberg
Date: Mon Jul 12 23:39:40 2010
New Revision: 963531
URL: http://svn.apache.org/viewvc?rev=963531&view=rev
Log:
WICKET-2943 introduce Component#onInitialize()
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Page.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/Page.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Page.java?rev=963531&r1=963530&r2=963531&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Page.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Page.java
Mon Jul 12 23:39:40 2010
@@ -1517,6 +1517,11 @@ public abstract class Page extends Marku
@Override
protected void onBeforeRender()
{
+ if (!getFlag(FLAG_INITIALIZED))
+ {
+ // initialize the page if not yet initialized
+ initialize();
+ }
super.onBeforeRender();
// If any of the components on page is not stateless, we need
to bind the session
// before we start rendering components, as then jsessionid
won't be appended
@@ -1546,17 +1551,6 @@ public abstract class Page extends Marku
}
/**
- * This method does nothing, it is here to prevent subclasses from
overriding it since this
- * callback is never called on the {...@link Page}
- *
- * @see org.apache.wicket.Component#onInitialize()
- */
- @Override
- protected final void onInitialize()
- {
- }
-
- /**
* Renders this container to the given response object.
*
* @param markupStream
@@ -1583,6 +1577,11 @@ public abstract class Page extends Marku
*/
final void componentAdded(final Component component)
{
+ if (!getFlag(Component.FLAG_INITIALIZED))
+ {
+ // initialize the page if not yet initialized
+ initialize();
+ }
dirty();
if (mayTrackChangesFor(component, component.getParent()))
{
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=963531&r1=963530&r2=963531&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
Mon Jul 12 23:39:40 2010
@@ -28,7 +28,7 @@ public class ComponentInitializationTest
{
public void testPropagation()
{
- Page page = new TestPage();
+ TestPage page = new TestPage();
TestComponent t1 = new TestComponent("t1");
TestComponent t2 = new TestComponent("t2");
@@ -59,13 +59,14 @@ public class ComponentInitializationTest
page.add(t1);
assertEquals(1, t4.getCount());
+ // test page was initialized
+ assertEquals(1, page.getCount());
}
-
public void testAtomicity()
{
- Page page = new TestPage();
+ TestPage page = new TestPage();
TestComponent t1 = new TestComponent("t1");
TestComponent t2 = new TestComponent("t2");
@@ -90,12 +91,26 @@ public class ComponentInitializationTest
page.add(t1);
assertEquals(1, t1.getCount());
assertEquals(1, t2.getCount());
+
+ // test page was only initialized once
+ assertEquals(1, page.getCount());
}
private static class TestPage extends WebPage
{
+ private int count = 0;
+ @Override
+ protected void onInitialize()
+ {
+ count++;
+ }
+
+ public int getCount()
+ {
+ return count;
+ }
}
private static class TestComponent extends WebMarkupContainer