GWT exporter cast exception from GWT.create; Tried to use mvp4g with GWT-Exporter but GWT.create didn't work

泄露秘密 提交于 2019-12-12 06:58:38

问题


I tried to use GWT-Exporter and it worked just fine when I copied the example. Then I tried to export an mvp4g Presenter Here's what I did:

@Export()
@Presenter(view = RegisterPluginDisplay.class)
public class RegisterPluginPresenterImpl extends BasePresenter<RegisterPluginView, MyBus implements RootPresenter { ... }

public interface RegisterPluginPresenter extends Exportable { ... }

//then in the start event I said:
ExporterUtil.exportAll();

It gave me this error:

Uncaught java.lang.AssertionErrorcom_mvp4g_client_Mvp4gModuleImpl_com_mvp4g_client_Mvp4gModuleGinjector_com_mvp4g_client_Mvp4gModule…:62 get_Key$type$com$joseph$draw4$client$presenter$RegisterPluginPresenterImpl$_annotation$$none$$_0_g$com_mvp4g_client_Mvp4gModuleImpl_com_mvp4g_client_Mvp4gModuleGinjectorImpl.java:34 getcom_joseph_draw4_client_presenter_RegisterPluginPresenterImpl_0_g$Mvp4gModuleImpl.java:101 createAndStartModule_0_g$Mvp4gEntryPoint.java:35 onModuleLoad_5_g$com_00046joseph_00046draw4_00046Draw4JUnit__EntryMethodHolder.java:3 init_2_g$ModuleUtils.java:44 initializeModules_0_g$Impl.java:247 apply_0_g$Impl.java:306 entry0_0_g$Impl.java:72 (anonymous function)ModuleUtils.java:55 gwtOnLoad_0_g$Map.java:29 (anonymous function)

I looked at the code and found that GWT.create() was unsucessful in creating the presenter. I tried to create an exported class and then using GWT.create on it and found that I can't use GWT.create with any class that implements Exportable even if I don't do ExporterUtils.exportAll(). The documentation for the Exportable interface says that the GWT.create() statement returns an Exportable. That explains the class cast exception. So how do I fix this?


回答1:


mvp4g uses GIN to create instances of presenters. GIN uses GWT.create(YourPresenter.class) to create an instance of the class.

As long as you don't have any deferred binding rule related to YourPresenter class GWT.create will behave like a new in Java.

In cases you are marking anything with the Exporter interface, the GWT Exporter Generator will be triggered. The generator create the exporter implementation which can not be used with mvp4g.




回答2:


I switched to using the experimental js interop and still got the same problem. Mvp4g uses gin to get the Presenter. According to the gin wiki "if GIN can't find a binding for a class, it falls back to calling GWT.create() on that class" in order to instantiate it. It can't use GWT.create on an Exportable because GWT.create(an Exportable) returns an Exporter. Like the documentation says you have to bind the class for it to not use GWT.create. The solution is to add a binding for the class. I just had to go in the configure method of my GinModule and add this line of code:

bind(MyPresenter.class).toProvider(MyPresenterProvider.class);

Then I had to create the MyPresenterProvider class:

public static class MyPresenterProvider.class implements Provider<MyPresenter> {
      @Override
    public MyPresenter get() {
        return new MyPresenter();
    }


来源:https://stackoverflow.com/questions/28134510/gwt-exporter-cast-exception-from-gwt-create-tried-to-use-mvp4g-with-gwt-exporte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!