I am trying to download the template file (Template.xls) from the server. But the Open / Save as dialogue box is not popping up to download the file. I am using Jboss eap 6.3
Here is my code,
OutputStream os = null;
InputStream is = null;
try {
URL resource = FacesContext.getCurrentInstance().getExternalContext().getResource("/WEB-INF/Template.xls");
is = resource.openStream();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse resp = (HttpServletResponse) facesContext.getExternalContext().getResponse();
resp.setHeader("Content-disposition", "attachment; filename=Template.xls");
resp.setContentType("application/vnd.ms-excel");
os = resp.getOutputStream();
IOUtils.copy(is, os);
os.flush();
facesContext.responseComplete();
} catch (Exception e) {
StatusMessages.instance().add(StatusMessage.Severity.ERROR, "Error occured while downloading IPS document");
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(is);
}
Calling this file template download in richfaces menu like his,
<rich:menuGroup style="font-size:10px;" label="Utilities" icon="img/TolMaintenance.png">
<rich:menuItem style="font-size:10px;" action="#{excelTemplate.downloadExcelTemplate}" label="Template" icon="img/catadmin.png" >
</rich:menuItem>
</rich:menuGroup>
There is no error message on the server log also the file is present in the server location and while debug I have seen the URL is pointing to the same location. I have checked the following link,
Open/Save as... dialog box not showing
The same issue I am facing. I have tried the suggestions provided over there but nothing is working out.
Can anyone please help me to fix the issue?