Reputation: 9649
i've encountered an issue on GWT codeserver parameter
in a simple scenario below,
Project structure
myapp
+src
++mypkg
---MainWindow.gwt.xml
---NextWindow.gwt.xml
+++client
----MainWindow.java
----NextWindow.java
+war
--MainWindow.html
--NextWindow.html
MainWindow.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='mainwindow'>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='mypkg.client.Mainwindow'/>
<source path='client'/>
</module>
MainWindow.java
package mypkg.client;
import com.google.gwt.core.client.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.ui.*;
public class MainWindow implements EntryPoint {
@Override
public void onModuleLoad() {
Button button = new Button("NextWindow!");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open("/NextWindow.html", null, null);
}
});
RootPanel.get().add(button);
}
}
MainWindow.html
<!doctype html>
<html>
<head>
<title>MainWindow</title>
<script type="text/javascript" language="javascript"
src="mainwindow/mainwindow.nocache.js"></script>
</head>
<body>
<h1>Hi, MainWindow!</h1>
</body>
</html>
NextWindow.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='nextwindow'>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='mypkg.client.NextWindow'/>
<source path='client'/>
</module>
NextWindow.java
package mypkg.client;
import com.google.gwt.core.client.*;
import com.google.gwt.user.client.ui.*;
public class NextWindow implements EntryPoint {
@Override
public void onModuleLoad() {
RootPanel.get().add(new Label("Hi, NewLabel!"));
}
}
NextWindow.html
<!doctype html>
<html>
<head>
<title>NextWindow</title>
<script type="text/javascript" language="javascript"
src="nextwindow/nextwindow.nocache.js"></script>
</head>
<body>
<h1>Hi, NextWindow!</h1>
</body>
</html>
On Devmode
launch the compiled myapp from the link,
http://127.0.0.1:8888/MainWindow.html?gwt.codesvr=127.0.0.1:9997
Click on button "NextWindow" then GWT browser plugin
pops up a complaint window,
Module NextWindow need be (re)compiled!
Confirm it then a new browser window is open from the link on Prodmode
,
http://127.0.0.1:8888/NextWindow.html
instead of the desired link on Devmode
,
http://127.0.0.1:8888/NextWindow.html?gwt.codesvr=127.0.0.1:9997
Consequently it displays only,
Hi, NextWindow!
But the very anticipated content below doesn't show up,
Hi, NewLabel!
If we trail GWT codeserver parameter
?gwt.codesvr=127.0.0.1:9997
to the source code, the problem could be solved by sacrificing the consistency on source level
between Devmode
and Prodmode
.
What are the preferable solutions indeed?
Upvotes: 0
Views: 402
Reputation: 3832
You can use if(GWT.isProdMode())
to check for Prodmode and Devmode, and trail the parameter if it is devmode.
That doesn't affect production mode - the gwt compiler is smart enough to just ignore devmode-code, so the devmode-block never makes it into the compiled javascript.
Upvotes: 1