创建由gin管理的新类实例

时间:2013-12-04 20:18:46

标签: gwt gwt-platform gin gwtp

我正在使用GWTP,正在使用他们的选项卡面板示例。我的问题是我需要演示一个搜索词,并在选项卡面板中添加一个新选项卡和搜索结果。所以,如果我搜索5次,我有5个标签。很容易,所以我想。

Gin广泛用于GWTP。所以我添加新标签的方法应该是简单的

tabPanel.addTab(new SearchDataGridView(), NameTokens.searchPage + 1);
由于SearchDataGridView类的构造函数

会让人感到困惑

@Inject
    SearchDataGridView(Binder uiBinder) {
        employeeDataProvider = new ListDataProvider<Employee>();

        initSearchGrid();

        initWidget(uiBinder.createAndBindUi(this));
    }

是的,我知道我还没有通过搜索词,我仍然试图让标签打开。

我的杜松子酒配置就是这个

bindPresenter(
                SearchDataGridPresenter.class,
                SearchDataGridPresenter.MyView.class,
                SearchDataGridView.class,
                SearchDataGridPresenter.MyProxy.class);

gwtp gin config

@Override
    protected void configure() {
        // RestDispatchAsyncModule.Builder dispatchBuilder = new RestDispatchAsyncModule.Builder();
        // install(dispatchBuilder.build());
        // install(new RestDispatchAsyncModule.Builder().build());

        install(new DefaultModule(DefaultPlaceManager.class));
        install(new ApplicationModule());

        bind(CurrentUser.class).in(Singleton.class);
        bind(IsAdminGatekeeper.class).in(Singleton.class);

        // DefaultPlaceManager Constants
        bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(ErrorPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(UnauthorizedPlace.class).to(NameTokens.homeNewsPage);
        bindConstant().annotatedWith(Names.named("rest")).to("http://localhost/services");
        // Google Analytics
        // bindConstant().annotatedWith(GaAccount.class).to("UA-8319339-6");

        // Load and inject CSS resources
        bind(ResourceLoader.class).asEagerSingleton();
    }

我如何解决这个问题?

感谢

使用下面的评论,sorta让它发挥作用。问题是我无法获取要显示的选项卡的内容。我在我的SearchContainer类的setInSlot方法中添加了调试代码,并意识到无论何时单击搜索选项卡,它都会触发此setInSlot方法,但它会将我的默认页面展示器列为内容。

@Override
    public void setInSlot(Object slot, IsWidget content) {
        Window.alert("fired setInSlot: " + slot.toString());
        Window.alert("fired setInSlot: " + content.toString());
        if (slot == ApplicationPresenter.TYPE_SetTabContent) {
            tabPanel.setPanelContent(content);
        } else {
            super.setInSlot(slot, content);
        }
    }

这就是我用来获取我的信息的方法。标签显示正常,视图中内置的jsonRPC调用正确执行,它只是不显示,这很奇怪。

我的主容器演示者的视图和代理由此

标识
public class ApplicationPresenter
        extends
        TabContainerPresenter<ApplicationPresenter.MyView, ApplicationPresenter.MyProxy> implements
        CurrentUserChangedHandler, AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler,
        ApplicationUiHandler {
    /**
     * {@link ApplicationPresenter}'s proxy.
     */
    @ProxyStandard
    public interface MyProxy extends Proxy<ApplicationPresenter> {
    }

    /**
     * {@link ApplicationPresenter}'s view.
     */
    public interface MyView extends TabView, HasUiHandlers<ApplicationUiHandler> {
        void refreshTabs();

        void setTopMessage(String string);
    }

我的问题可能与我的内容类型有关吗?这是我为所有类型定义的内容

/**
     * This will be the event sent to our "unknown" child presenters, in order for them to register their tabs.
     */
    @RequestTabs
    public static final Type<RequestTabsHandler> TYPE_RequestTabs = new Type<RequestTabsHandler>();

    /**
     * Fired by child proxie's when their tab content is changed.
     */
    @ChangeTab
    public static final Type<ChangeTabHandler> TYPE_ChangeTab = new Type<ChangeTabHandler>();

    /**
     * Use this in leaf presenters, inside their {@link #revealInParent} method.
     */
    @ContentSlot
    public static final Type<RevealContentHandler<?>> TYPE_SetTabContent = new Type<RevealContentHandler<?>>();

3 个答案:

答案 0 :(得分:1)

执行此操作的正确方法是使用PresenterWidgetProvider

ClientModule中,您可以定义:

bindPresenterWidget(SearchDataGridPresenter.class, SearchDataGridPresenter.MyView.class, SearchDataGridView.class);

Presenter添加SearchDataGridView Provider注入@Inject public SeachContainerPresenter(final Provider<SearchDataGridPresenter> seachDataGridProvider) { }

addToSlot(TYPE_SetSearchDataGridContent,seachDataGridProvider.get())

对于每次搜索,您都会在SearchContainerPresenter中致电SearchContainerView

addToSlot()中覆盖@Override public void addToSlot(Object slot,Widget content) { if (slot == SeachContainerPresenter.TYPE_SetSearchDataGridContent) { tabPanel.addTab(content, NameTokens.searchPage + 1); } else { super.addToSlot(slot,content); } } 方法:

{{1}}

答案 1 :(得分:0)

查看binding everything together。我认为您必须将演示者的AsyncProvider添加到yuor Ginjector。

AsyncProvider<SearchDataGridPresenter> getSearchDataGridPresenter();

答案 2 :(得分:0)

您可以在GIN Injector中放置SearchDataGridView getSearchDataGridView()方法并调用它以获取SearchDataGridView实例。