我有问题,我不明白。我想我已经完成了我应该做的事情,但它确实有效。
我无法使用ui处理程序从视图中执行presenter方法。错误说我没有设置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 。也许它应该与标准Presenter不同。任何帮助赞赏。
答案 0 :(得分:1)
好吧,我已经自己解决了。
问题在于此演示者/视图对是一个小部件。所以它应该与gwtp的插槽机制实现一致。为此,我们使用带有Presenter类参数的bind方法(不像我正在做的那样查看)。
@Inject UploaderPresenter fileUploaderPresenter;
@Override
protected void onBind() {
super.onBind();
setInSlot(SLOT_FILE_UPLOAD, fileUploaderPresenter);
}
以下是文档:
http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html
部分:
答案 1 :(得分:0)
好的,让我们跟踪代码中的步骤:
这是演示者的构造函数。此处注入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构造函数。因此,在Presenter的构造函数中设置它们之前,请调用this.getUiHandlers()。
将呼叫转移到某种@UiHandler