GWTP ViewWithUiHandlers:未设置 uiHandlers。您是否从视图的构造函数中调用了getUiHandlers()?在演示者小部件中



我有不明白的问题。我想我已经做了我应该做的事情,但它不起作用。

我无法使用 ui 处理程序从视图中执行演示器方法。错误说我没有设置 ui 处理程序,但我确实设置了:

@Inject
FileUploaderPresenter(EventBus eventBus, MyView view, PlaceManager placeManager) {
   super(eventBus, view);
   getView().setUiHandlers(this);
   this.placeManager = placeManager;
}

public FileUploaderView() {
   super();
   this.getUiHandlers();
   this.initWidget(uploader);
}

但是我收到一个错误:

com.gwtplatform.mvp.client.ViewWithUiHandlers
SEVERE: uiHandlers are not set.  Did you call getUiHandlers() from your view's constructor?

肯定会发布我所有相关的课程:

public class FileUploaderModule extends AbstractPresenterModule {
    @Override
    protected void configure() {
        bindSingletonPresenterWidget(FileUploaderPresenter.class, FileUploaderPresenter.MyView.class, FileUploaderView.class);
    }
}

public class FileUploaderPresenter extends PresenterWidget<FileUploaderPresenter.MyView> implements FileUploaderUiHandlers {
    interface MyView extends View, HasUiHandlers<FileUploaderUiHandlers> {
    }
    PlaceManager placeManager;
    @Inject
    FileUploaderPresenter(EventBus eventBus, MyView view, PlaceManager placeManager) {
    super(eventBus, view);
        getView().setUiHandlers(this);
    this.placeManager = placeManager;
    }
    @Override
    protected void onBind() {
    super.onBind();
    }
    @Override
    public void onOk() {
    Routing.Redirect.toLoginPage(placeManager);
    }
    @Override
    public void onUnauthorized() {
    Routing.Redirect.toLoginPage(placeManager);
    }
}

interface FileUploaderUiHandlers extends UiHandlers {
    void onUnauthorized();
    void onOk();
}

public class FileUploaderView extends ViewWithUiHandlers<FileUploaderUiHandlers> implements FileUploaderPresenter.MyView {
    MaterialFileUploader uploader = new MaterialFileUploader();
    public FileUploaderView() {
        super();
        this.getUiHandlers();
        this.initWidget(uploader);
        MaterialUploadLabel label = new MaterialUploadLabel();
        label.setTitle("Put Your's files here and here");
        label.setDescription("Some description here");
        uploader.add(label);
        uploader.setMaxFileSize(10000000);
        uploader.setUrl(ServiceRouting.FULL_SERVICE +           ServiceRouting.FileService.upload);
    addHandlers();
    }
    private void addHandlers() {
    uploader.addUnauthorizedHandler(new UnauthorizedHandler<UploadFile>() {
        @Override
        public void onUnauthorized(UnauthorizedEvent<UploadFile> event) {
        GWT.log("UnauthorizedEvent (" + event.getTarget().getName() + " | " + event.getResponse().getCode() + " | " + event.getResponse().getMessage() + "|" + event.getResponse().getBody()
            + ")");
        MaterialToast.fireToast("Redirect to login page");
        getUiHandlers().onUnauthorized();
        }
    });
}

我通过以下方式实例化这个小部件: FileUploaderView()

是否发生此错误,因为我不使用 uiBinder?这是我的第一个PresenterWidget。也许它应该以与标准演示器不同的方式完成。任何帮助表示赞赏。

好吧,我自己想通了。

问题是这个演示者/视图对是一个小部件。所以它应该用gwtp的插槽机制进行实例化。为此,我们使用带有表示器类参数的绑定方法(不像我所做的那样查看)。

@Inject UploaderPresenter fileUploaderPresenter;
@Override
protected void onBind() {
    super.onBind();
    setInSlot(SLOT_FILE_UPLOAD, fileUploaderPresenter);
}

以下是文档:

http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html

部分:

  • 绑定演示者小组件
  • 设置在插槽中
  • 绑定插槽

http://dev.arcbees.com/gwtp/core/presenters/

好的,让我们从您的代码中跟踪步骤:

这是演示器的构造函数。 这里注入MyView view已经在这里创建,以传递给您的构造函数。

 @Inject
FileUploaderPresenter(EventBus eventBus, MyView view, PlaceManager placeManager) {
   super(eventBus, view);
   getView().setUiHandlers(this)

这意味着

public FileUploaderView() {
   super();
   this.getUiHandlers();
   this.initWidget(uploader);
}

称为 BEFORE 演示者构造器。因此,在Presenter的构造函数中设置它们之前,请调用this.getUiHandlers()。

将呼叫移动到某种@UiHandler

相关内容

  • 没有找到相关文章

最新更新