Using the Frame class, and adding Elements to it directly - doesn't display?
38 views
Skip to first unread message
King_V
unread,
Jun 5, 2012, 4:22:44 PM6/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
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.
Thomas Broyer
unread,
Jun 5, 2012, 6:24:18 PM6/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-we...@googlegroups.com
You're adding your elements as children of the frame, which is used as a fallback in case the browser does support frames. You should add them to the document that's displayed within the frame.
King_V
unread,
Jun 6, 2012, 12:13:04 PM6/6/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
Thomas,
Thanks. I think I might be missing something very obvious, because
I'm looking at the APIs, and I have no idea how to do what you're
suggesting.
Code-wise, how do I get the document within the frame, so that I can
add the new Elements to it?
- Joe
Thomas Broyer
unread,
Jun 6, 2012, 12:46:39 PM6/6/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-we...@googlegroups.com
On Wednesday, June 6, 2012 6:13:04 PM UTC+2, King_V wrote:
Thomas,
Thanks. I think I might be missing something very obvious, because
I'm looking at the APIs, and I have no idea how to do what you're
suggesting.
Code-wise, how do I get the document within the frame, so that I can
add the new Elements to it?