If you create 2 SmartGWT components but add only one to the DOM, some events do not work. Here is a usecase:
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
You must put all your SmartGWT widgets as a child of a GwtBridge widget. The previous use case become:
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
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); } }
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(); } }
Code:
public class MyEntryPoint ... { private FlowPanel getFlowPanel(final String name) { ... GwtBridge c = new GwtBridge(); ... } ... }
Olivier
Comment