2012-07-25 59 views
0

我正在使用GWT 2.4,SmartGWT 3.0,GWTP 0.7。GWTP,SmartGWT,将GWT小部件添加到SmartGWT时出错

我主要尝试为我的布局坚持使用SmartGWT小部件,但我试图添加一个GWT小部件(可以是从MapWidget到HighCharts或GWT标签的ChartWidget)到SmartGWT标签集中的选项卡。然后我得到以下例外:

Caused by: java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list 

这只发生在开发模式。在生产中,断言已被关闭,并且我的小部件确实出现,但它使得在Dev模式下无法进行调试。据我了解这是因为我混合了SmartGWT和GWT小部件。

在GWTP之前,我能够完成这项工作,因为要显示我的UI,我会在我的根布局上调用draw(),这是一个VLayout。现在我使用的是GWTP,当我启动RevealRootContentEvent时,它会显示我的布局,它会通过调用RootPanel.get().add(...)来添加布局,我认为这是我现在遇到这些问题的原因。我所有的布局仍然在SmartGWT中。

有没有人遇到同样的问题(在相同的设置中)以及如何处理?

+0

你不能摆脱''RootPanel.get()。add()'并且只使用'draw'方法吗?你的问题直接与'RootPanel.get()。add()'调用 – 2012-07-25 10:56:51

+0

直接相关我没有直接调用RootPanel.get()。add()。这在GWTP的RootPresenter.setInSlot中完成。我想你的建议是克隆GWTP源,并制作我自己的定制版本? – 2012-07-25 11:31:06

+0

那么为什么不重写setinslot呢? – 2012-07-25 11:44:57

回答

3

所以我想我已经到了我的问题的底部。

我看这个问题 http://code.google.com/p/gwt-platform/issues/detail?id=127

在职位之一,它展示了如何创建一个自定义RootPresenter。该RootPresenter还包含一个RootView,其中上述setInSlot方法放置,并通过编写自定义视图,它可以覆盖该方法,并确保draw()上调用SmartGWT的布局,而不是在RootPanel.get().add(...);

添加

我IMPL看起来是这样的:

public class CustomRootPresenter extends RootPresenter 
{ 
    public static final class CustomRootView extends RootView 
    { 
     @Override 
     public void setInSlot(Object slot, Widget content) 
     { 
      if (content instanceof Layout) 
      { 
       // clear 
       RootLayoutPanel.get().clear(); 
       RootPanel.get().clear(); 

       Layout layout = (Layout) content; 
       layout.draw(); 
      } 
      else 
      { 
       super.setInSlot(slot, content); 
      } 
     } 
    } 

    @Inject 
    public CustomRootPresenter(EventBus eventBus, CustomRootView myRootView) 
    { 
     super(eventBus, myRootView); 
    } 
} 

记住你的GIN模块中注入定制根主持人:

// don't use install, when using custom RootPresenter 
// install(new DefaultModule(ClientPlaceManager.class)); 

bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class); 
bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(Singleton.class); 
bind(CustomRootPresenter.class).asEagerSingleton(); 
bind(PlaceManager.class).to(ClientPlaceManager.class).in(Singleton.class); 
bind(GoogleAnalytics.class).to(GoogleAnalyticsImpl.class).in(Singleton.class); 

这肯定与解决我的问题将GWT小部件添加到SmartGWT布局。

感谢让米歇尔加西亚推动我朝着正确的方向发展! :)