I have created two module name module1 and module2 in gwt application. I want to pass message from module1 to module2 and module2 to module1 simultaneously after some seconds. I write the following code, but it gives me error unable to find module1.gwt.xml in classpath.
public void onModuleLoad() {
mainBus.fireEvent(new PingEvent("-----Simulation Started-----"));
}
module1
public void onModuleLoad()
{
GWTEventBus.mainBus.addHandler(PingEvent.TYPE, new PingEventHandler(){
public void onEvent(PingEvent event) {
System.out.print("Inside Ping --> ");
new Timer(){
public void run() {
GWTEventBus.mainBus.fireEvent(new PongEvent("Pong fired..."));
}
}.schedule(1000);
}
});
}
module2
public void onModuleLoad()
{
//final SimpleEventBus mainBus = new SimpleEventBus();
GWTEventBus.mainBus.addHandler(PongEvent.TYPE, new PongEventHandler(){
public void onEvent(PongEvent event) {
System.out.print("Inside Pong1 --> ");
new Timer(){
public void run() {
GWTEventBus.mainBus.fireEvent(new PingEvent("Ping fired..."));
}
}.schedule(1000);
}
});
}
plz help me.
If you are trying to have two separated modules (*.nocache.js files) included in the same webpage, you can not pass messages unless you use JS.
Use JSNI to export some method from module1 so as it is available in javascript, then call this method from module2 using JSNI as well.
Note that using JSNI, you have to pass messages based on primitive types (see documentation)
BTW: I'd rather use gwtexporter to export methods and classes I want available in JS, and gwtquery to call JS methods instead of using JSNI.
Your app can only have one entry point, but you can have your main module inherit multiple other gwt apps. I would suggest looking into module inheritance. You can inherit a module in your .gwt.xml file, and that module will be loaded, and its onModuleLoad method will be called automatically.
https://developers.google.com/web-toolkit/doc/latest/DevGuideOrganizingProjects#DevGuideModules