我使用的是GWT2.4,GWTP3.0,SmartGWT 0.7。
我主要尝试在布局中使用SmartGWT小部件,但我正在尝试将GWT小部件(可以是从MapWidget到来自HighCharts的ChartWidget或GWT标签的任何内容)添加到SmartGWT选项卡集的选项卡。然后我得到以下异常:
Caused by: java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list这只会在Dev模式下发生。在生产环境中,断言已被关闭,我的小部件也会显示出来,但这使得无法在Dev模式下进行调试。据我所知,这是因为我混合了SmartGWT和GWT。
在GWTP出现之前,我能够做到这一点,因为为了显示我的UI,我会在根布局上调用draw(),这是一个VLayout。现在我正在使用GWTP,当我触发RevealRootContentEvent时,它将显示我的布局,并且它将通过调用RootPanel.get().add(...)来添加布局,我认为这就是我现在遇到这些问题的原因。我所有的布局仍然在SmartGWT中。
有没有人遇到过同样的问题(在相同的设置中),如何处理?
发布于 2012-08-13 14:50:15
所以我想我找到了问题的症结所在。
我读了这期http://code.google.com/p/gwt-platform/issues/detail?id=127
在其中一篇文章中,展示了如何创建自定义RootPresenter。RootPresenter还包含一个RootView,上面提到的setInSlot方法就放在其中,通过编写自定义视图,可以覆盖该方法,并确保在SmartGWT布局上调用draw(),而不是在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模块中注入自定义root presenter:
// 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);它绝对解决了我向SmartGWT布局添加GWT小部件的问题。
感谢Jean-Michel Garcia推动我朝着正确的方向前进!:)
https://stackoverflow.com/questions/11647010
复制相似问题