gwtgwtpgwt-platform

GWTP ViewWithUiHandlers: uiHandlers are not set. Did you call getUiHandlers() from your view's constructor? in PresenterWidget


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.


Solution

  • 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/