Reputation: 5331
I have problem that I do not understand. I think I've done what I supposed to do, but it dosnt work.
I cannot executed presenter methods from view using ui handlers. Error says that I did not set ui handlers but I did:
@Inject
FileUploaderPresenter(EventBus eventBus, MyView view, PlaceManager placeManager) {
super(eventBus, view);
getView().setUiHandlers(this);
this.placeManager = placeManager;
}
and
public FileUploaderView() {
super();
this.getUiHandlers();
this.initWidget(uploader);
}
But I am getting an error:
com.gwtplatform.mvp.client.ViewWithUiHandlers
SEVERE: uiHandlers are not set. Did you call getUiHandlers() from your view's constructor?
For sure I will post all my classes related:
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();
}
});
}
I instantialize this widget with: FileUploaderView()
Is this error happens, cause I don't use uiBinder? This is my first PresenterWidget. Maybe it should be done differently from standard Presenter. Any help appreciated.
Upvotes: 0
Views: 487
Reputation: 5331
Alright, I've figure it out on my own.
The problem is that This Presenter/View pair is a widget. So it should be instantialize with slot mechanism of gwtp. And to do this we use bind method with Presenter class parameter (not view like I was doing).
@Inject UploaderPresenter fileUploaderPresenter;
@Override
protected void onBind() {
super.onBind();
setInSlot(SLOT_FILE_UPLOAD, fileUploaderPresenter);
}
Here is documentation:
http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html
sections:
http://dev.arcbees.com/gwtp/core/presenters/
Upvotes: 1
Reputation: 1128
Ok, just let's trace the steps from your code:
This is the constructor of your presenter. MyView view
injected here WAS ALREADY CREATED here to be passed to your constructor.
@Inject
FileUploaderPresenter(EventBus eventBus, MyView view, PlaceManager placeManager) {
super(eventBus, view);
getView().setUiHandlers(this)
which means
public FileUploaderView() {
super();
this.getUiHandlers();
this.initWidget(uploader);
}
is called BEFORE presenter contructor. So you call this.getUiHandlers() before you set them in Presenter's constructor.
Move the call to some kind of @UiHandler
Upvotes: 0