【问题标题】:GWTP, SmartGWT, Error when adding GWT widget to SmartGWTGWTP、SmartGWT、将 GWT 小部件添加到 SmartGWT 时出错
【发布时间】:2012-07-25 09:46:26
【问题描述】:

我正在使用 GWT 2.4、SmartGWT 3.0、GWTP 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

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

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

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

【问题讨论】:

  • 你不能摆脱RootPanel.get().add()而只使用draw方法吗?您的问题与RootPanel.get().add() 通话直接相关
  • 我没有直接调用 RootPanel.get().add()。这是在 GWTP 的 RootPresenter.setInSlot 中完成的。我猜你的建议是克隆 GWTP 源,并制作我自己的自定义版本?
  • 为什么不覆盖 setinslot 呢?
  • 我不知道该怎么做。我有我的 LoginPresenter,它扩展了 Presenter。在这里我可以重写 setInSlot(Object slot, PresenterWidget> content),但是这个方法永远不会被调用。与从 ViewImpl 扩展的 LoginView 相同。这里我可以重写 setInSlot(Object slot, Widget content),但是这个也永远不会被调用。
  • ...或者您是否提到克隆 GWTP src 并在那里覆盖 setInSlot? (因为现在我试图在我自己的代码中覆盖该特定方法,该方法使用原始 gwtp src)

标签: gwt smartgwt gwtp


【解决方案1】:

所以我想我找到了问题的根源。

我读过这个问题 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);

它确实解决了我将 GWT 小部件添加到 SmartGWT 布局的问题。

感谢 Jean-Michel Garcia 将我推向正确的方向! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2016-08-27
    相关资源
    最近更新 更多