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

2007-10-05 Thread Kent Tong


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2007-10-05 Thread Kent Tong


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;htmlgt;
lt;bodygt;
lt;span wicket:id=\quot;listView\quot;gt;lt;span
wicket:id=\quot;labelWithDetachableModel\quot;gt;testlt;/spangt;lt;/spangt;
lt;/bodygt;
lt;/htmlgt;

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2007-10-04 Thread Dan Syrstad
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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




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

2007-10-02 Thread Dan Syrstad
On 10/1/07, Kent Tong [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




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

2007-10-02 Thread Kent Tong


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2007-10-01 Thread Dan Syrstad
So the contract of the method has changed since 1.2.6?
-Dan

On 10/1/07, Igor Vaynberg [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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

2007-10-01 Thread Igor Vaynberg
guess so

-igor


On 10/1/07, Dan Syrstad [EMAIL PROTECTED] wrote:

 So the contract of the method has changed since 1.2.6?
 -Dan

 On 10/1/07, Igor Vaynberg [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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