You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dan Syrstad <ds...@ener-j.org> on 2007/10/01 18:01:59 UTC

Page.detachModels() not working like it used to

Anyone know why Page.detachModels() no longer detaches the models of all
child components in 1.3beta3? There is a bunch of code commented out in
Page.detachModels() that previously did this. Now it just calls
super.detachModels() (on Component) which apparently just detaches the model
immediately attached to the Page (which renders the need for
Page.detachModels() moot). I searched the lists and the closest thing I
found was a reference to https://issues.apache.org/jira/browse/WICKET-418,
but that seems to have to do with Ajax requests.

This has broken a JUnit test that was testing a detachable model using
WicketTester. The same test passes in Wicket 1.2.6. Is there something
different I should be doing in 1.3?

-Dan

Re: Page.detachModels() not working like it used to

Posted by Igor Vaynberg <ig...@gmail.com>.
guess so

-igor


On 10/1/07, Dan Syrstad <ds...@ener-j.org> wrote:
>
> So the contract of the method has changed since 1.2.6?
> -Dan
>
> On 10/1/07, Igor Vaynberg <ig...@gmail.com> wrote:
> >
> > i think the way it works now is that there is a visitor that goes
> through
> > the hierarchy and calls detach() on every component. so there is no need
> > for
> > detachmodels to do much more then detach the models for the current
> > component only.
> >
> > -igor
> >
> >
> > On 10/1/07, Dan Syrstad <ds...@ener-j.org> wrote:
> > >
> > > Anyone know why Page.detachModels() no longer detaches the models of
> all
> > > child components in 1.3beta3? There is a bunch of code commented out
> in
> > > Page.detachModels() that previously did this. Now it just calls
> > > super.detachModels() (on Component) which apparently just detaches the
> > > model
> > > immediately attached to the Page (which renders the need for
> > > Page.detachModels() moot). I searched the lists and the closest thing
> I
> > > found was a reference to
> > https://issues.apache.org/jira/browse/WICKET-418,
> > > but that seems to have to do with Ajax requests.
> > >
> > > This has broken a JUnit test that was testing a detachable model using
> > > WicketTester. The same test passes in Wicket 1.2.6. Is there something
> > > different I should be doing in 1.3?
> > >
> > > -Dan
> > >
> >
>

Re: Page.detachModels() not working like it used to

Posted by Dan Syrstad <ds...@ener-j.org>.
So the contract of the method has changed since 1.2.6?
-Dan

On 10/1/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> i think the way it works now is that there is a visitor that goes through
> the hierarchy and calls detach() on every component. so there is no need
> for
> detachmodels to do much more then detach the models for the current
> component only.
>
> -igor
>
>
> On 10/1/07, Dan Syrstad <ds...@ener-j.org> wrote:
> >
> > Anyone know why Page.detachModels() no longer detaches the models of all
> > child components in 1.3beta3? There is a bunch of code commented out in
> > Page.detachModels() that previously did this. Now it just calls
> > super.detachModels() (on Component) which apparently just detaches the
> > model
> > immediately attached to the Page (which renders the need for
> > Page.detachModels() moot). I searched the lists and the closest thing I
> > found was a reference to
> https://issues.apache.org/jira/browse/WICKET-418,
> > but that seems to have to do with Ajax requests.
> >
> > This has broken a JUnit test that was testing a detachable model using
> > WicketTester. The same test passes in Wicket 1.2.6. Is there something
> > different I should be doing in 1.3?
> >
> > -Dan
> >
>

Re: Page.detachModels() not working like it used to

Posted by Igor Vaynberg <ig...@gmail.com>.
i think the way it works now is that there is a visitor that goes through
the hierarchy and calls detach() on every component. so there is no need for
detachmodels to do much more then detach the models for the current
component only.

-igor


On 10/1/07, Dan Syrstad <ds...@ener-j.org> wrote:
>
> Anyone know why Page.detachModels() no longer detaches the models of all
> child components in 1.3beta3? There is a bunch of code commented out in
> Page.detachModels() that previously did this. Now it just calls
> super.detachModels() (on Component) which apparently just detaches the
> model
> immediately attached to the Page (which renders the need for
> Page.detachModels() moot). I searched the lists and the closest thing I
> found was a reference to https://issues.apache.org/jira/browse/WICKET-418,
> but that seems to have to do with Ajax requests.
>
> This has broken a JUnit test that was testing a detachable model using
> WicketTester. The same test passes in Wicket 1.2.6. Is there something
> different I should be doing in 1.3?
>
> -Dan
>

Re: Page.detachModels() not working like it used to

Posted by Kent Tong <ke...@cpttm.org.mo>.

Dan Syrstad-2 wrote:
> 
> Your page code is almost exactly the same as mine. However, your HTML does
> not look correct - it has no tag with a wicket:id in it. So maybe your
> component never rendered.
> 

No, your mail client has stripped the code. Let me show you the code again:

&lt;html&gt;
&lt;body&gt;
&lt;span wicket:id=\&quot;listView\&quot;&gt;&lt;span
wicket:id=\&quot;labelWithDetachableModel\&quot;&gt;test&lt;/span&gt;&lt;/span&gt;
&lt;/body&gt;
&lt;/html&gt;

public class Test extends WebPage {
	public Test() {
		ListView listView = new ListView("listView", Arrays
				.asList(new String[] { "a", "b" })) {

			protected void populateItem(final ListItem item) {
				item.add(new Label("labelWithDetachableModel", new
LoadableDetachableModel() {
					protected Object load() {
						return item.getModelObject();
					}
				}));
			}

		};
		add(listView);
	}
}

Run the test case and it will pass (although for the wrong reason).


-- 
View this message in context: http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13063392
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Page.detachModels() not working like it used to

Posted by Dan Syrstad <ds...@ener-j.org>.
Your page code is almost exactly the same as mine. However, your HTML does
not look correct - it has no tag with a wicket:id in it. So maybe your
component never rendered.

I still get an exception using Wicket 1.3.0-beta3.

You say "After startPage() returns, the page has been detached". Evidently
this is not true in 1.3.0beta3 because my first assertion "assertTrue(
childModel.isAttached())" succeeds (it is attached), which would indicate
that the child model was never detached. If the Page had been detached, the
child component and its model should have been as well. ... Which is the
whole point of this thread.

On 10/5/07, Kent Tong <ke...@cpttm.org.mo> wrote:
>
>
>
> Dan Syrstad-2 wrote:
> >
> > Actually, Page.detach() is not callable from a JUnit test that uses
> > WicketTester in 1.3.0beta3. It throws an exception:
> >
>
> I used your code and the test passed. Here is my test page:
>
>
> <html>
> <body>
> test
> </body>
> </html>
> public class Test extends WebPage {
>         public Test() {
>                 ListView listView = new ListView("listView", Arrays
>                                 .asList(new String[] { "a", "b" })) {
>
>                         protected void populateItem(final ListItem item) {
>                                 item.add(new
> Label("labelWithDetachableModel", new
> LoadableDetachableModel() {
>                                         protected Object load() {
>                                                 return item.getModelObject
> ();
>                                         }
>                                 }));
>                         }
>
>                 };
>                 add(listView);
>         }
> }
>
>
> However, I really think your test case is broken. After startPage()
> returns,
> the page has been detached. Why it passes on my computer is because
> of your call to debugComponentTrees(). Therefore, you should really be
> testing if the model is now detached. That's it. By checking the output
> you can be sure that the model was once attached.
>
> --
> Kent Tong
> Wicket tutorials freely available at http://www.agileskills2.org/EWDW
> --
> View this message in context:
> http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13057290
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Page.detachModels() not working like it used to

Posted by Kent Tong <ke...@cpttm.org.mo>.

Dan Syrstad-2 wrote:
> 
> Actually, Page.detach() is not callable from a JUnit test that uses
> WicketTester in 1.3.0beta3. It throws an exception:
> 

I used your code and the test passed. Here is my test page:


<html>
<body>
test
</body>
</html>
public class Test extends WebPage {
	public Test() {
		ListView listView = new ListView("listView", Arrays
				.asList(new String[] { "a", "b" })) {

			protected void populateItem(final ListItem item) {
				item.add(new Label("labelWithDetachableModel", new
LoadableDetachableModel() {
					protected Object load() {
						return item.getModelObject();
					}
				}));
			}

		};
		add(listView);
	}
}


However, I really think your test case is broken. After startPage() returns,
the page has been detached. Why it passes on my computer is because
of your call to debugComponentTrees(). Therefore, you should really be
testing if the model is now detached. That's it. By checking the output 
you can be sure that the model was once attached.

--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
-- 
View this message in context: http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13057290
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Page.detachModels() not working like it used to

Posted by Dan Syrstad <ds...@ener-j.org>.
Actually, Page.detach() is not callable from a JUnit test that uses
WicketTester in 1.3.0beta3. It throws an exception:

org.apache.wicket.WicketRuntimeException: No RequestCycle is currently set!
at org.apache.wicket.Component.getRequest(Component.java:1443)
at org.apache.wicket.Page.onDetach(Page.java:1406)
at org.apache.wicket.markup.html.WebPage.onDetach(WebPage.java:360)
at org.apache.wicket.Component.detach(Component.java:899)


In 1.2.6, you could call Page.detachModels() and the test would run fine.

-Dan

Here's my test:

---------------------
import junit.framework.TestCase;
/*
//1.2.6
import wicket.Component;
import wicket.Page;
import wicket.model.LoadableDetachableModel;
import wicket.util.tester.WicketTester;
*/

//1.3
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.tester.WicketTester;

public class WicketDetachTest extends TestCase {
    public WicketDetachTest()     {     }

    public void testDetach()    {
        WicketTester tester = new WicketTester();
        Page page = tester.startPage(Wicket12Page.class);

        tester.debugComponentTrees();

        Component c = tester.getComponentFromLastRenderedPage
("listView:0:labelWithDetachableModel");
        LoadableDetachableModel childModel =
(LoadableDetachableModel)c.getModel();

        // Child currently attached due to rendering
        assertTrue(childModel.isAttached()); // Attached

        // Detach children
        //page.detachModels();  // 1.2.6 - Does not detach child models in
1.3
        page.detach(); // 1.3 <---- FAILS - not in request cycle

        assertFalse(childModel.isAttached()); // Not attached

        // Cause attachment
        c.getModelObject();
        assertTrue(childModel.isAttached()); // Attached
    }
}


On 10/2/07, Kent Tong <ke...@cpttm.org.mo> wrote:
>
>
>
> Dan Syrstad-2 wrote:
> >
> > Nope. I tried detach() too and that doesn't work - the test still fails.
> I
> > had to write my own method which was basically was a copy of the old
> > Page.detachModels() code.
> >
> > The thing is that  In beta3, Page now just acts like a Component as far
> as
> > detachModels() is concerned and Component.detachModels()/detach() does
> > notdetach all of the child models.
> > Component.detach(), in fact, calls detachChildren() which is an empty
> > method.
> >
>
> detachChildren() is overriden by MarkupContainer which does detach its
> children
> (see below). So there must be something wrong with your unit test.
>
>         void detachChildren()
>         {
>                 // Loop through child components
>                 final Iterator iter = iterator();
>                 while (iter.hasNext())
>                 {
>                         // Get next child
>                         final Component child = (Component)iter.next();
>
>                         // Call end request on the child
>                         child.detach();
>                 }
>                 super.detachChildren();
>         }
> --
> View this message in context:
> http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13000103
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Page.detachModels() not working like it used to

Posted by Kent Tong <ke...@cpttm.org.mo>.

Dan Syrstad-2 wrote:
> 
> Nope. I tried detach() too and that doesn't work - the test still fails. I
> had to write my own method which was basically was a copy of the old
> Page.detachModels() code.
> 
> The thing is that  In beta3, Page now just acts like a Component as far as
> detachModels() is concerned and Component.detachModels()/detach() does
> notdetach all of the child models.
> Component.detach(), in fact, calls detachChildren() which is an empty
> method.
> 

detachChildren() is overriden by MarkupContainer which does detach its
children
(see below). So there must be something wrong with your unit test.

	void detachChildren()
	{
		// Loop through child components
		final Iterator iter = iterator();
		while (iter.hasNext())
		{
			// Get next child
			final Component child = (Component)iter.next();

			// Call end request on the child
			child.detach();
		}
		super.detachChildren();
	}
-- 
View this message in context: http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a13000103
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Page.detachModels() not working like it used to

Posted by Dan Syrstad <ds...@ener-j.org>.
On 10/1/07, Kent Tong <ke...@cpttm.org.mo> wrote:
>
>
>
> Dan Syrstad-2 wrote:
> >
> > This has broken a JUnit test that was testing a detachable model using
> > WicketTester. The same test passes in Wicket 1.2.6. Is there something
> > different I should be doing in 1.3?
> >
>
> If it was calling detach() instead of detachModels(), then it should
> continue
> to pass.


Nope. I tried detach() too and that doesn't work - the test still fails. I
had to write my own method which was basically was a copy of the old
Page.detachModels() code.


I think the change was made so that a component (not a page) can detach
> its children and their models without relying on the page. This is needed
> when handling an AJAX request.


The thing is that  In beta3, Page now just acts like a Component as far as
detachModels() is concerned and Component.detachModels()/detach() does
notdetach all of the child models.
Component.detach(), in fact, calls detachChildren() which is an empty
method.

--
> View this message in context:
> http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a12991427
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Page.detachModels() not working like it used to

Posted by Kent Tong <ke...@cpttm.org.mo>.

Dan Syrstad-2 wrote:
> 
> This has broken a JUnit test that was testing a detachable model using
> WicketTester. The same test passes in Wicket 1.2.6. Is there something
> different I should be doing in 1.3?
> 

If it was calling detach() instead of detachModels(), then it should
continue
to pass.

I think the change was made so that a component (not a page) can detach 
its children and their models without relying on the page. This is needed 
when handling an AJAX request.
-- 
View this message in context: http://www.nabble.com/Page.detachModels%28%29-not-working-like-it-used-to-tf4549247.html#a12991427
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org