1

l split my GWT code in different different modules like

PrintPermit.gwt.xml

EmployeeResponse.gwt.xml

Rejected.gwt.xml

and every module has its own entry point class

in my HTML host page I am calling script like

ae.init.EmployeeResponse.nocache.js

I have a menu like

Print Application

Reject Application

New application

whenever user will click on new application default new application will open as I declare EmployeeResponse.nocache.js statically in my HTML host page.

now I want to call other modules on click button print and reject button

how can i call nocache js for print and reject modules. is there any way to dynamic call. please help me guys.

Community
  • 1
  • 1
nitin verma
  • 616
  • 1
  • 6
  • 22
  • Can I ask what is the purpose of such a split? I haven't seen it before; if you're looking to just download code on an "as-needed" basis, GWT has code split features for this; also, if the modules ever need to communicate between them it would complicate things further. – Andrei Jun 21 '17 at 10:49
  • Depending on the size of an application this might be useful. It was discussed in the past. Search for TurDucken. – El Hoss Jun 21 '17 at 11:17
  • @Andrei I am agree with you actually I have a different GWT existing project which have only two functionality for all applications, print and reject. I was thinking to open the print module on click print and reject as well. hope now you understand my problem – nitin verma Jun 21 '17 at 11:41
  • So, in short, use other GWT modules like a JS library? (it is important to know if they're going to manipulate the DOM *at all*) – Andrei Jun 21 '17 at 12:07
  • yes exactly but I do not have any Idea how can I do that, could you please give me some steps in answer. – nitin verma Jun 21 '17 at 12:13
  • IMO you should not do that! You should not use fake-split within the same APP. There are really big APPs with pretty reasonable compilation times. If your compilation time is a disaster you should find the problem. Split points solve this problem and so the client only download the required JS and it is loaded asynchronously automatically! You might use different split point if there are really different and independent modules. A good example is a chat app, you develop the chat app independently but you can integrate it (ex. open a chat room) within your app using events, JsInterop, etc. – Ignacio Baca Jun 22 '17 at 09:33
  • the problem is not completion time I just want to load nocache when the module is required because I have 3 modules and I am integrating one module with different framework, now tell me the best solution what should I do. – nitin verma Jun 22 '17 at 12:28

3 Answers3

1

Here's how I've done it in the past:

  • First of all, in the module you want to export, you need to make sure that the code you're going to export doesn't end up obfuscated. This can be accomplished with the liberal use of @JsType; this is the new way of exporting JS, available in GWT 2.8 (as opposed to JSNI).
  • Your module's entry point onModuleLoad can be empty; it doesn't need to do anything.
  • Include your JS in the HTML you want to use (maybe the same page as your "main" module)
  • Check JSInterop documentation (perhaps the one available here) on how you can use native JS in your GWT app (because now, your GWT module became native JS). Import the classes via JSInterop from your library, and use them.

Please be aware of the async nature of the GWT JS loading; your library will be loading in an async manner, just like any JS application (and therefore, it won't be available immediately when your page loads). To overcome this, I've placed a call to a native JS function in my library's onModuleLoad function (i.e. to make sure you notify any potential listeners that the code has loaded; because when onModuleLoad runs, the code surely loaded).

Andrei
  • 1,613
  • 3
  • 16
  • 36
  • @ Andrei I am not talking about module communication. I want to load nocahche dynamically as per module without refreshing. – nitin verma Jun 21 '17 at 13:42
  • Then perhaps your question becomes "how to load JS inside another JS", as described [here](https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file)? – Andrei Jun 21 '17 at 13:44
  • not it all I think my concern is not clear, ok let me explain. I have two GWT module with two different HTML and nochache file. now if i toggle between them on click then every time my browser will refresh. so what I did I create a new GWT project and with modules. now the problem is how will I call these modules ? – nitin verma Jun 21 '17 at 13:52
  • In the new project you've created (let's call it `P`), how will you use these two modules (let's call them `M1` and `M2`) : in the `.nocache.js` form, or in their `java` form? – Andrei Jun 21 '17 at 13:55
  • ok lets assume first my project ( p) will load then there is two button M1 and M2 now I want to load nochache as per button click m1 and m2 – nitin verma Jun 21 '17 at 14:04
  • 1
    In this case, my answer above still stands, with the difference that step 3 changes to loading via `ScriptInjector` (which is GWT's way of dynamically loading JS). See here : http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/ScriptInjector.html – Andrei Jun 21 '17 at 14:06
  • one thing more this ScriptInjector will override this existing script tag or every time will create new script tag – nitin verma Jun 21 '17 at 14:26
  • I **suspect** (but not sure) that it creates a new script every time; I usually run it within an initialization function, so I haven't stumbled upon this use case. But I guess you can place a flag somewhere in the `$wnd` where you mark the fact that you've loaded a particular script to avoid doing so again. – Andrei Jun 21 '17 at 14:30
1

There is a example of an InterAppEventBus:

https://github.com/sambathl/interapp-eventbus

which shows the communication between two GWT applications. I have adopted it and replaced JSNI with Elemental2 and WebStorage:

https://github.com/FrankHossfeld/InterAppEventBus

Hope that helps.

El Hoss
  • 3,767
  • 2
  • 18
  • 24
0

You can achieve this through separate Html file for each module.

So first of all create separate html for each application e.g. PrintPermit.html and specify corresponding nocache.js in each html.

then on your buttons in menu, add click handlers and in each on click load a corresponding html through Window.open()

e.g. for PrintPermit,

printPermitButton.addClickHandler(new ClickHandler{
        @Override
        public void onClick(ClickEvent arg0) {
              String s = GWT.getHostPageBaseURL() + "PrintPermit.html";
                Window.open(s, "PrintPermit", "");
        }
});

Please note the window.open will open in new tab in browser, you can also use gwt iframe to open html in same browser page.

Each module will have corresponding nocache.js and will be loaded through html using Window.open()

vsbehere
  • 666
  • 1
  • 7
  • 23
  • the advantages of GWT over JSP is that you can change a page without a browser refresh/fetch flicker. thats why I am trying to find a way to change nochache dynamically. – nitin verma Jun 21 '17 at 13:39