1

問題があります。mvp4g フレームワークでアプリを開発しています。タブ付きの 1 つのビューがあり、1 つのタブがタブ付きの 2 番目のビューです。2 番目のビューからプレゼンターを呼び出そうとすると、NPE (プレゼンターが null) が発生します。最初のビューのコードは次のとおりです。

public interface ICategoriesView extends IsWidget {

    public interface ICategoriesPresenter {
    }
}

@Presenter(view = CategoriesView.class)
public final class CategoriesPresenter extends BasePresenter<ICategoriesView, UserEventBus> implements ICategoriesPresenter {
}

public final class CategoriesView extends ReverseCompositeView<ICategoriesPresenter> implements ICategoriesView {

    interface CategoriesViewUiBinder extends UiBinder<Widget, CategoriesView> {
    }

    private static final CategoriesViewUiBinder UI_BINDER = GWT.create(CategoriesViewUiBinder.class);

    public CategoriesView() {
        initWidget(UI_BINDER.createAndBindUi(this));
    }
}


<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:container="urn:import:com.sencha.gxt.widget.core.client.container"
             xmlns:gxtClient="urn:import:com.sencha.gxt.widget.core.client"
             xmlns:category="urn:import:app.client.ui.settings.categories">

    <ui:with type="app.client.Messages"             field="messages"/>
    <ui:with type="app.client.resource.image.Image" field="imageUser"/>

    <!-- Tab configuration. -->
    <ui:with type="com.sencha.gxt.widget.core.client.TabItemConfig" field="subjectTypes">
        <ui:attributes text="{messages.categories_tab_subjectTypes}" />
    </ui:with>
    <ui:with type="com.sencha.gxt.widget.core.client.TabItemConfig" field="subjectRegions">
        <ui:attributes text="{messages.categories_tab_subjectRegions}" />
    </ui:with>
    <ui:with type="com.sencha.gxt.widget.core.client.TabItemConfig" field="tripTypes">
        <ui:attributes text="{messages.categories_tab_tripTypes}" />
    </ui:with>
    <ui:with type="com.sencha.gxt.widget.core.client.TabItemConfig" field="expenseTypes">
        <ui:attributes text="{messages.categories_tab_expenseTypes}" />
    </ui:with>
    <ui:with type="com.sencha.gxt.widget.core.client.TabItemConfig" field="expensePaymentTypes">
        <ui:attributes text="{messages.categories_tab_expensePaymentTypes}" />
    </ui:with>

    <container:SimpleContainer>
        <gxtClient:TabPanel addStyleNames="margin-10">
            <gxtClient:child config="{subjectTypes}">
                <category:CategoryView category="ONE" />
            </gxtClient:child>

            <gxtClient:child config="{subjectRegions}">
                <category:CategoryView category="TWO" />
            </gxtClient:child>

            <gxtClient:child config="{tripTypes}">
                <category:CategoryView category="THREE" />
            </gxtClient:child>

            <gxtClient:child config="{expenseTypes}">
                <category:CategoryView category="FOUR" />
            </gxtClient:child>

            <gxtClient:child config="{expensePaymentTypes}">
                <category:CategoryView category="FIVE" />
            </gxtClient:child>
        </gxtClient:TabPanel>
    </container:SimpleContainer>

</ui:UiBinder>

2番目のビューのコードは次のとおりです。

public interface ICategoryView extends IsWidget, Editor<CategoryDTO> {

    public interface ICategoryPresenter {

        public void getCategory(CategoryList category);
    }

    public void setCategory(String category);

    public void setGridContent(List<CategoryDTO> categoryDTOList);

    void showFailedMessage();
}


@Presenter(view = CategoryView.class)
public final class CategoryPresenter extends BasePresenter<ICategoryView, UserEventBus> implements ICategoryPresenter {

    @Inject
    private CategoryServiceAsync categoryServiceAsync;

    public void getCategory(CategoryList category) {
       ...
    }
}

public final class CategoryView extends ReverseCompositeView<ICategoryPresenter> implements ICategoryView {

    interface CategoryViewUiBinder extends UiBinder<Widget, CategoryView> {
    }

    interface CategoryDriver extends SimpleBeanEditorDriver<CategoryDTO, CategoryView> {
    }

    private static final CategoryViewUiBinder UI_BINDER = GWT.create(CategoryViewUiBinder.class);

    public CategoryView() {
        initWidget(UI_BINDER.createAndBindUi(this));
    }

    public void setCategory(String category) {
        List<CategoryDTO> categoryDTOList = Collections.emptyList();
        presenter.getCategory(CategoryList.valueOf(category));  // PRESENTER IS NULL!!!
    }

    public void setGridContent(List<CategoryDTO> categoryDTOList) {
    }

    @Override
    public void showFailedMessage() {
    }
}
4

1 に答える 1

0

プレゼンターに onGoTo メソッドがありませんか? イベントバスを見せてもらえますか? コードをコンパイルして、スタック トレースをここにコピーしてみてください。

于 2014-03-15T13:51:33.977 に答える