Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    problem when removing button from slot

    Hi,

    I have 2 buttons in 2 slots ('slot1' and 'slot2'). When removing button from slot1, the button in slot2 stops working (throws javascript error on click).

    Here is my code:

    GWT:

    Code:
    package com.gwt.tableTest.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.DOM;
    import com.google.gwt.user.client.Window;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.Button;
    
    public class Test implements EntryPoint {
    
        static Button b = new Button("dynamic button");
    
        public void onModuleLoad() {
            addStaticButton();
            addDynamicButton();
            publishStaticMethods();
        }
    
        public static void addDynamicButton() {
            b.addClickHandler(new ClickHandler(){
                public void onClick(ClickEvent event) {
                    Window.alert("clicked on dynamic");
                }
            });
            DOM.getElementById("slot1").appendChild(b.getElement());
        }
    
        private void addStaticButton(){
            Button t = new Button("static button");
            t.addClickHandler(new ClickHandler(){
                public void onClick(ClickEvent event) {
                    Window.alert("clicked on static");
                }
            });
            DOM.getElementById("slot2").appendChild(t.getElement());
        }
    
        public static void removeDynamicButton(){
             DOM.getElementById("slot1").removeChild(b.getElement());
        }
    
        public static native void publishStaticMethods() /*-{
            $wnd.removeButton = function(){
    @com.gwt.tableTest.client.Test::removeDynamicButton()();
            };
        }-*/;
    
    }
    HTML code:
    Code:
    <html>
    <head>
    </head>
                      
    <body>
    
    <div id="slot2"></div>
    <div id="slot1"></div>
    
    <script language="javascript" src="/webtools/tableTest/com.gwt.tableTest.Table.nocache.js"></script>
    
    <button onclick="removeButton();">remove button from gwt</button>
    </body>
    </html>
    Can you please advice a solution?

    thank you
    Last edited by la123; 7 May 2009, 06:03.
Working...
X