How to remove a GWT widget from the Dom using native javascript?

833 views
Skip to first unread message

darkflame

unread,
Feb 22, 2009, 7:42:58 PM2/22/09
to Google Web Toolkit
I'm not too good with Javascript, but this is what I got;

var removethis = $wnd.getElementById('fade');
removethis.parentNode.removeChild(oNodeToRemove);


But this seems to cause a crash, despite the fact that (checking
firebug) the element I want to remove certainly has the ID set to
fade.
I'm using this as part of a redefined close-header for a GWT Dialogue,
incidently. (the close functionality is working just fine, the full
function is;

private native void redefineClose(DialogBox dialogBox) /*-{
$wnd['closeDialog'] = function () {

dialogBox.@com.google.gwt.user.client.ui.DialogBox::hide()();

var removethis = $wnd.getElementById('fade');
removethis.parentNode.removeChild(oNodeToRemove);



}

}-*/;

)

Darkflame

unread,
Feb 22, 2009, 7:46:05 PM2/22/09
to Google Web Toolkit
*correction I was using;

var removethis = $doc.getElementById('fade');
removethis.parentNode.removeChild(oNodeToRemove);

(not $wnd, before anyone points that out)

On Feb 23, 1:42 am, darkflame <darkfl...@gmail.com> wrote:
> I'm not too good with Javascript, but this is what I got;
>
>                var removethis = $wnd.getElementById('fade');
>                    removethis.parentNode.removeChild(oNodeToRemove);
>
> But this seems to cause a crash, despite the fact that (checking
> firebug) the element I want to remove certainly has the ID set to
> fade.
> I'm using this as part of a redefined close-header for a GWT Dialogue,
> incidently. (the close functionality is working just fine, the full
> function is;
>
>         private native void redefineClose(DialogBox dialogBox) /*-{
>            $wnd['closeDialog'] = function () {
>
>            dialogB...@com.google.gwt.user.client.ui.DialogBox::hide()();

davidroe

unread,
Feb 22, 2009, 11:58:53 PM2/22/09
to Google Web Toolkit
because the child you are trying to remove is oNodoToRemove, not
removeThis?

/dave

Darkflame

unread,
Feb 23, 2009, 5:04:07 AM2/23/09
to Google Web Toolkit
Sorry, that was just another mistake copying, I can assure you it also
dosnt work with the correct;

var removethis = $doc.getElementById('fade');
removethis.parentNode.removeChild(removethis);

Darkflame

unread,
Feb 23, 2009, 8:01:34 AM2/23/09
to Google Web Toolkit
If it helps, I've discovered it does work in Firefox, but not IE.
So I'm guessing a difference in the removeChild function?

Jason Essington

unread,
Feb 23, 2009, 2:46:36 PM2/23/09
to Google-We...@googlegroups.com
You must like memory leaks ...

If you manage to remove a widget from DOM this way, you leave in tact
the link between GWT and DOM preventing any objects removed from being
garbage collected.

Is there some reason you can not simply perform a
widget.removeFromParent() completely negating the need to muck about
in DOM yourself?

-jason

Darkflame

unread,
Feb 23, 2009, 3:20:31 PM2/23/09
to Google Web Toolkit
Because it has to be triggered when native redefineClose fires.
As I said, I'm not too good with javascript, I'm using the native
function as a way to get my own close icon in the corner of the
dialogue box's header.

I'm using a techique I read here;
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/2950c44985a26cdf/fefcfcf5644959ba

Which works great, but means the close is triggering native
javascript.
Unless theres some way, in turn, to get that to trigger a normal
removeFromParent() ?

Darkflame

unread,
Mar 1, 2009, 5:16:21 AM3/1/09
to Google Web Toolkit
Bump

Anyone got any ideas?

I think the "proper" way to do it is to get the native javascript to
in turn trigger the gwt code again to remove it cleanly, but I dont
have a clue how to do this.

On 23 feb, 21:20, Darkflame <darkfl...@gmail.com> wrote:
> Because it has to be triggered when native redefineClose fires.
> As I said, I'm not too good with javascript, I'm using the native
> function as a way to get my own close icon in the corner of the
> dialogue box's header.
>
> I'm using a techique I read here;http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...

Daniel Kurka

unread,
Mar 1, 2009, 7:45:21 AM3/1/09
to Google-We...@googlegroups.com

Darkflame

unread,
Mar 3, 2009, 9:40:49 AM3/3/09
to Google Web Toolkit
perfect!

mywidget.@com.darkflame.client.mywidgetclass::hide()();

Did the trick nicely.

On Mar 1, 1:45 pm, Daniel Kurka <kurka.dan...@googlemail.com> wrote:
> read up on calling java code from javascript:http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=goog...
>
> 2009/3/1 Darkflame <darkfl...@gmail.com>
Reply all
Reply to author
Forward
0 new messages