I’ve attached the test code that works (in two ways), from main window and subwindow, that if I paste in main app doesn’t work (from subwindow)
I’ve also attached two images of the traffic it generates. Main app calls on the subwindow but immediately replaces it with a GET request that shows the above described behaviour. The test app shows two requests and return the file properly.
Have no ideea why main app does a 302 redirect with this. I’ve had a domain name set in hosts file set up for 127.0.0.1 and that’s it (I removed it, also need to restart or something?). Also my router is set up to forward requests to that computer (but their incoming), not originating from the same computer, as I’m working on it…
One noticeable difference I can think of is that main application widgetset is built differently, to load resources dynamically… but I doubt that’s it
Anyone has any ideea what could be the problem please?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" />
<generate-with class="view.MyWidgetMapGenerator">
<when-type-is class="com.vaadin.terminal.gwt.client.WidgetMap" />
</generate-with>
<inherits name="org.vaadin.vaadinvisualizations.widgetset.VaadinvisualizationApplicationWidgetset" />
<inherits name="com.vaadin.addon.timeline.gwt.TimelineWidgetSet" />
</module>
Changed
getApplication().getMainWindow().open(sr);
to
event.getButton().getWindow().open(sr);
and now the result in the main app is that the download starts, but the content of the subwindow is wiped out.
the traffic not consists of two requests as in the test app, the first regular request, as in the test app, but the GET request that shouldn’t be there comes immediately after
[b]
I need to stop making this GET request… or make it not affect the window conten… how? What does the window content have to do with it anyway? It has been set as attachment…
[/b]
Some variation of the code I picked up from a bug fix that produces the same result as above:
class DownloadResource extends StreamResource {
private final String filename;
public DownloadResource(StreamSource streamSource, String name,
Application application) {
super(streamSource, name, application);
filename = name;
}
@Override
public DownloadStream getStream() {
DownloadStream stream = new DownloadStream(getStreamSource()
.getStream(), "text/plain", filename);
stream.setParameter("Content-Disposition", "attachment;filename="
+ filename);
return stream;
}
}
...
try {
ApplicationContext ctx = getApplication().getContext();
WebApplicationContext webCtx = (WebApplicationContext) ctx;
ServletContext sc = webCtx.getHttpSession()
.getServletContext();
String path = sc.getRealPath("\\WEB-INF\\classes")
+ "\\project_metrics.xml";
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(
path));
char[] buf = new char[1024]
;
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024]
;
}
reader.close();
Window w = event.getButton().getWindow();
final String data = fileData.toString();
StreamSource streamSource = new StreamSource() {
public InputStream getStream() {
return new ByteArrayInputStream(data.getBytes());
}
};
w.open(new DownloadResource(streamSource,
"project_metrics.xml", event.getButton()
.getApplication()));
} catch (IOException e1) {
e1.printStackTrace();
}