Question

I am having an issue getting an initial RPC call to load data when the module is loaded.

I am adapting code from here and here.

The error that if fails on is a null pointer, and it behaves as if it is not even making the RPC call at all, since neither debug messages inside of the RPC appear in the test console in Eclipse.

The MenuItems object is an ArrayList < ArrayList < String > > object that implements IsSerializable and has a SerializableWhiteList entry as per this SO answer. This object is generated in an RPC RemoteServiceServlet.

The console also references the line

History.fireCurrentHistoryState();

in AppController.java (almost identical to the GWT Contacts example)

Ideas on why/where/how this is going astray? Any other implementation examples of initial RPC calls would be great also.

public class MVPtest implements EntryPoint {

    MenuItems mItems;

    public void onModuleLoad() {
        MainServiceAsync rpcService = GWT.create(MainService.class);

        System.out.println("Inside of mod load. rpcService = " + rpcService.toString());

        rpcService.getMenuItems(new AsyncCallback<MenuItems>() {

            public void onFailure(Throwable caught) {
                System.out.println("I failed...");
                caught.printStackTrace();
            }

            public void onSuccess(MenuItems result) {
                System.out.println("I got the menuitems.");
                mItems = result;
            }

        });
        HandlerManager eventBus = new HandlerManager(null);
        AppController appViewer = new AppController(rpcService, eventBus, mItems);
        appViewer.go(RootLayoutPanel.get());
    }
}

The rpcService debug message yields a non-null:

Inside of mod load. rpcService = com.******.******.test.client.MainService_Proxy@4f07f3b5
Was it helpful?

Solution

This statement is dangerous:

AppController appViewer = new AppController(rpcService, eventBus, mItems);

because your code on the client side will be executed without witing for the response of your call.

Something like this should work:

public class MVPtest implements EntryPoint {

    MenuItems mItems;

    public void onModuleLoad() {
        MainServiceAsync rpcService = GWT.create(MainService.class);

        System.out.println("Inside of mod load. rpcService = " + rpcService.toString());

        rpcService.getMenuItems(new AsyncCallback<MenuItems>() {

            public void onFailure(Throwable caught) {
                System.out.println("I failed...");
                caught.printStackTrace();
            }

            public void onSuccess(MenuItems result) {
                System.out.println("I got the menuitems.");
                mItems = result;
                HandlerManager eventBus = new HandlerManager(null);
                AppController appViewer = new AppController(rpcService, eventBus, mItems);
                appViewer.go(RootLayoutPanel.get());
           }

        });
     }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top