I have a button which invokes Java code, where a Doc
file gets created and later it's given to a client.
I do it with the following code onclick event:
var v = new ru.generate.doc.generateDoc();
v.generateReport2();
Inside the generateReport2() method I have another method which gives a document to the client. It's implemented like this:
private void giveDocumentForClient(String pathToCompleteFile) throws InvalidFormatException, IOException
{
String fn = new File(pathToCompleteFile).getName();
XspHttpServletResponse response = (XspHttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(URLConnection.guessContentTypeFromName(fn));
response.setHeader("Content-disposition", "attachment; filename=" + fn);
OutputStream output = response.getOutputStream();
output.write(IOUtils.toByteArray(new FileInputStream(new File(pathToCompleteFile))));
output.close();
FacesContext.getCurrentInstance().responseComplete();
}
And it works so well, but still there is some problem. After this code gets executed, and the client hits the Save button, the page where this button is located gets 'freezed' and the client is unable to click anything ever since.
The button properties are set to default - full update.
How to avoid this? Thanks in advance.
Add the client-side JS call XSP.allowSubmit()
to your button in order to allow new submits after pressing the button.
See this answer too and other similar answers.