How to create multiple excel files and open for user to download. I am using next code for one, if I do it again , one after the other, I get two excels, but both are the one that is created second.
code to create first excel
GotrPersClass gotrPersClas = ...;
try {
FileResource res;
res = ReportTakeAway.generateCustomExcel1(gotrPersClas, office, dateF, dateT);
if (res != null) {
setResource("dlexcel", res);
ResourceReference rr = ResourceReference.create(res, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
code to create second excel
List<Map<String, Object>> rs = ...;
try {
FileResource resClass;
resClass = ReportTakeAway.generateCustomExcel2(rs, office, dateF, dateT);
if (resClass != null) {
setResource("dlexcel", resClass);
ResourceReference rr = ResourceReference.create(resClass, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
both codes are one after another
found this link, but is not for java:
I believe the problem is in the lines
setResource("dlexcel", resClass);
ResourceReference rr = ResourceReference.create(resClass, this, "dlexcel");
which create the reference for the client (browser) in both cases. So regardless which download the user chooses, the file referenced as 'dlexel' will only provide one of the two.
Try to have unique values for the parameter 'key'.