Tuesday, June 5, 2012

Using the Frame class, and adding Elements to it directly - doesn't display?

All,

I've got this very short program, and I don't understand why it's not
working. I am creating a Frame object, trying to append element
children to it, and while the Frame instance seems to be aware of its
children, they do not get displayed.

Here is what I have. What am I doing wrong? When I attach to the
RootPanel, I get a blank rectangular square with nothing in it.
Inspection with Firebug also shows that the head and body elements are
empty.


public class TestFrameAndElement implements EntryPoint {

public void onModuleLoad() {
Frame frame = new Frame();
Element html = DOM.createElement("html");
Element head = DOM.createElement("head");
Element body = DOM.createElement("body");
Element element = DOM.createElement("div");
element.setInnerHTML("<span>hello</span><span style=\"color: blue;
\">goodbye</span>");
html.appendChild(head);
html.appendChild(body);
body.appendChild(element);
frame.getElement().appendChild(html);
RootPanel.get().add(frame);
System.out.println("Frame children: " +
frame.getElement().getChildCount());
System.out.println("HTML children : " +
frame.getElement().getChild(0).getChildCount());
System.out.println("HEAD children : " +
frame.getElement().getChild(0).getChild(0).getChildCount());
System.out.println("BODY children : " +
frame.getElement().getChild(0).getChild(1).getChildCount());
System.out.println("DIV children : " +
frame.getElement().getChild(0).getChild(1).getChild(0).getChildCount());
}
}

I've also noticed that if I do NOT add any elements, there is still an
html/head/body in the Frame section when I inspect with Firebug, but
in the code, the first sysout returns 0 and of course I have to
comment out the rest of the sysout statements.

How do I correctly work with this?

Thanks.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment