Announcement

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

    [Tip] Mixing SmartGWT and GWT - use a special widget

    If you create 2 SmartGWT components but add only one to the DOM, some events do not work. Here is a usecase:

    Code:
    public class MyEntryPoint ... {
        private FlowPanel getFlowPanel(final String name)
        {
            IButton b1 = new IButton(name);
            b1.addClickHandler(new ClickHandler()
            {
                @Override
                public void onClick(ClickEvent event)
                {
                    Window.alert(name + " clicked");
                }
            });
            Canvas c = new Canvas();
            c.addChild(b1);
            FlowPanel f1 = new FlowPanel();
            f1.add(c);
            return f1;
        }
    
        public void onModuleLoad()
        {
            final FlowPanel f1 = getFlowPanel("one");
            final FlowPanel f2 = getFlowPanel("two");
            RootPanel.get().add(f1);
            new Timer()
            {
                @Override
                public void run()
                {
                    RootPanel.get().add(f2);
                }
            }.schedule(5000);
        }
    }
    First, the f1 panel is shown, not the f2. The IButton in the f1 panel does not work. Five seconds later, the f2 panel is added to the DOM. Then, the IButton of f1 and of f2 work fine. Really funny ;)

    To avoid this problem, you need to hide a SmartGWT component as soon it is not in the DOM tree. You can do it by hand or use this class

    Code:
        public class GwtBridge
            extends Canvas
        {
            public MyCanvas()
            {
                setVisible(false);
            }
    
    
            @Override
            protected void onAttach()
            {
                super.onAttach();
                show();
            }
    
    
            @Override
            protected void onDetach()
            {
                super.onDetach();
                hide();
            }
        }
    You must put all your SmartGWT widgets as a child of a GwtBridge widget. The previous use case become:

    Code:
    public class MyEntryPoint ... {
        private FlowPanel getFlowPanel(final String name)
        {
            ...
            GwtBridge c = new GwtBridge();
            ...
        }
        ...
    }
    And all works fine. For us, it also cover some other issue at once ;). Fell free to copy, change, adapt or include this code in your own libraries/products.

    Olivier

    #2
    Try

    f1.draw()

    instead of

    RootPanel.get().add(f1);

    and see if that helps.

    Comment


      #3
      f1 is a FlowPanel. So draw does not exists. My goal is to add a SmartGWT widget to a GWT panel. So I can't call draw. The only working solution (I know) is the one I explain here. And It's working fine.

      I think including the GwtBridge widget to SmartGWT would help everyone wanting to include a SmartGWT widget in a GWT panel.

      Comment

      Working...
      X