RootPanel.get().clear() does not clear the page

196 views
Skip to first unread message

go canal

unread,
Feb 7, 2010, 9:46:41 PM2/7/10
to google-we...@googlegroups.com
Hi,
I try to add RootPanel.get().clear() in the callback but it does not clear anything. If I use RootPanel.get("nameofcontainer").clear(), then it works - that widget is removed.
 
I am using the default greet example. GWT 2.0.1, Chrome browser. This is how I create the widgets:

 

RootPanel.get(

"nameFieldContainer").add(nameField);

RootPanel.get(

"passwordFieldContainer").add(passwordField);

RootPanel.get(

"sendButtonContainer").add(sendButton);

RootPanel.get(

"errorLabelContainer").add(errorLabel);

Did I understand RootPanel.get().clear() correctly - I thought it will clear everything on the page
 
rgds,
canal

Ashar Lohmar

unread,
Feb 9, 2010, 9:35:06 AM2/9/10
to Google Web Toolkit
Hi
the clear() method on the HasWidgets objects only removes the child
widgets that had been added to it by using the add method
in you case the logic is kind of ok, the
RootPanel.get("nameofcontainer") is a child of RootPanel.get() in the
DOM point of view, but
but not for the HasWidgets object represented by the RootPanel.get()

an work around would be to do something like
RootPanel.get().getElement().setInnerHTML(""); but the when you'll try
an RootPanel.get("nameofcontainer") you'll get nothing because there
will no more be an object with the id=nameofcontainer

also it's possible to end up with "artifacts" object that you may have
in memory but don't exist in the page/document (i don't know if this
is true for sure).
hope I managed to explain it so that you could understand my point
good luck in finding a solution, or if you'll come back with more
details of what you want to achieve maybe I/we would be able to help
more.

On Feb 8, 4:46 am, go canal <goca...@yahoo.com> wrote:
> Hi,
> I try to add RootPanel.get().clear() in the callback but it does not clear anything. If I use RootPanel.get("nameofcontainer").clear(), then it works - that widget is removed.
>
> I am using the default greet example. GWT 2.0.1, Chrome browser. This is how I create the widgets: 
> RootPanel.get(

> RootPanel.get(
> RootPanel.get(
> RootPanel.get("nameFieldContainer").add(nameField);"passwordFieldContainer").add(passwordField);"sendButtonContainer").add(sendButton);"errorLabelContainer").add(errorLabel);

go canal

unread,
Feb 10, 2010, 2:49:52 AM2/10/10
to google-we...@googlegroups.com
Hi,
Thanks for your reply.
I have not tested but I think getElement().setInnerHTML will work.
 
First, I thought that I can juse use RootPanel.get().clear() to remove everything on the current page; then I hope I can use something like RootPanel.get("id").clear() if I have sometign like this in my html file:
 <div id="id"></div>
But it does not work.
 
So looks like I need to use setInnerHTML.
 
rgds,
canal



From: Ashar Lohmar <ashar...@gmail.com>
To: Google Web Toolkit <google-we...@googlegroups.com>
Sent: Tue, February 9, 2010 10:35:06 PM
Subject: Re: RootPanel.get().clear() does not clear the page
--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Thomas Broyer

unread,
Feb 10, 2010, 6:27:26 AM2/10/10
to Google Web Toolkit

On Feb 10, 8:49 am, go canal <goca...@yahoo.com> wrote:
> Hi,

> Thanks for your reply.
> I have not tested but I think getElement().setInnerHTML will work.
>
> First, I thought that I can juse use RootPanel.get().clear() to remove everything on the current page; then I hope I can use something like RootPanel.get("id").clear() if I have sometign like this in my html file:
>  <div id="id"></div>

> But it does not work..


>
> So looks like I need to use setInnerHTML.

You should really use the clear() method of your different RootPanels,
or you'll leak memory (until the user leaves the page and/or closes
his browser window/tab).

Reply all
Reply to author
Forward
0 new messages