On 10 sep, 13:40, hjo1620 <hjo1...@gmail.com> wrote:
> CustomerComponent extends Composite,
> I do panel.add(widget) for all my widgets,
> and then do initWidget(panel), in the constructor.
>
> However this GWTTestCase test fails:
>
> public void testShouldAttachAllWidgets() throws Exception {
>             CustomerComponent component = new CustomerComponent();
>             assertNotNull(component);
>             assertTrue(component.hasWidget());
>             LinkedHashMap<String, Widget> widgets =
> component.getWidgets();
>             Iterator<Widget> it = widgets.values().iterator();
>             while (it.hasNext()) {
>                         assertTrue(it.next().isAttached());
>             }
>
> }
>
> What am I missing ?
> Should they not have been attached by the panel.add(widget) ?

No, after panel.add(widget), all widget has is a parent
(widget.getParent() != null).

Being "attached" in GWT means you're attached to the *document* (i.e.
by walking the parents of the widget's element, you'll find the <body>
and then the <html> elements of $doc).
In other words, if component (hence panel) isn't itself attached, its
children (widget) can't be attached.
For your test to pass, you'd have to do something like RootPanel.get
().add(component); this would attach component (because a RootPanel is
a wrapper around an existing, "attached", element, it is inherently
attached, so when you add(component), component is automatically
"attached" too; as well as its children)
Well, actually, such a test would actually test GWT's behavior rather
your component's behavior; IMO your test should rather assertSame
(component, it.next().getParent()).

...assuming the assertion failure is in the latest assertTrue in your
code, of course...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to