user2080198
user2080198

Reputation: 11

GWT Code splitting. Splited file not load intime

I have a problem. In large GWT(2.4)-app i desided used gwt-code-splitting. GWT-compiller cropped app for a small js-parts.

but, whean I want to load some module

final Module form = ModuleFactory.getInstance().getModule(modumesName);

/*/

private Module module = null;

public Module getModule(String moduleName){
 if (moduleName.equals("M1")) {
 GWT.runAsync(new RunAsyncCallback() {      
        @Override
        public void onSuccess() {
            module = GWT.create(M1.class);
        }

        @Override
        public void onFailure(Throwable arg0) {
            Window.alert("not load M1");
        }
    });
  }
return module;
}

M1 extend Module

When I call creating widget M1 at first time, I got a js error

"Uncaught com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses "

but, on other time, im got my module M1. In development tools I saw, that split part loaded.

public class CreateModuleWidget extends Composite{
     private static final Binder binder = GWT.create(Binder.class);
     interface Binder extends UiBinder<Widget, CreateModuleWidget> {}

     public CreateModuleWidget() {
           /*initparams**/ 
     }

     @UiHandler("createButt")
     void onCreateClick(ClickEvent event) {
          String modumesName = "M1";
          final WidgetDialog dialog = new WidgetDialog(moduleName, true);
          final Module form = ModuleFactory.getInstance().getModule(modumesName);
          dialog.setDialogWidget(form);
          dialog.show();
     }
}

public class ModuleFactory{
    private Module form = null;

private static ModuleFactory instance = null;

public static ModuleFactory getInstance(){
    if(instance == null){
        instance = new ModuleFactory();
    }
    return instance;
}
    public Module getModule(String moduleName){
        if (moduleName.equals("M1")) {
           GWT.runAsync(new RunAsyncCallback() {        
        @Override
        public void onSuccess() {
            module = GWT.create(M1.class);
        }

        @Override
        public void onFailure(Throwable arg0) {
            Window.alert("not load M1");
        }
    });
          }
    return module;
   }
 }

Uncaught com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses BDC16B1A93B4190A8C1DD66EEF9838B8.cache.html:1435 (anonymous function)

Upvotes: 0

Views: 226

Answers (2)

user1258245
user1258245

Reputation: 3639

Typically I do this as part of MVC.

Controller checks if the module it needs is null, if so it loads it and then proceeds to the view after obtaining the needed code.

Module module;



   if (module==null){

          //You could display a waiting message in a dialog

          GWT.runAsync(new RunAsyncCallback() {  
           ...
            public void onSuccess() {
                  module = GWT.create(M1.class);
                  showXYZView();
             }
     });

    }else{
          showXYZView();
    }

Upvotes: 0

Thomas Broyer
Thomas Broyer

Reputation: 64541

Well, you know, it's called runAsync for a reason: it's a-synchronous.

Upvotes: 1

Related Questions