@SkipDialog
public class HtmlFormBuilderDownload extends HtmlFormBuilderItem {
@Override
public void renderView() {
HtmlOutputText output = new HtmlOutputText();
output.setValue(Messages.getStringJSF("download.label.default"));
if (properties.getFile() == null || properties.getFile().getFilesize() == 0) {
HtmlInputFile input = new HtmlInputFile();
input.setId("download" + getItemUuid());
addLabeledComponent(output, input);
HtmlCommandButton submit = new HtmlCommandButton();
submit.setValue(Messages.getStringJSF("download.submit"));
getChildren().add(submit);
} else {
try {
File tempFile = File.createTempFile(properties.getFile().getFilename(), "");
try (FileOutputStream out = new FileOutputStream(tempFile)) {
out.write(properties.getFile().getFile());
out.flush();
out.close();
}
HtmlOutputText link = new HtmlOutputText();
link.setEscape(false);
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
link.setValue("<a target=\"_blank\" href=\"" + request.getContextPath() + "/" + FileServlet.FOLDER + "/" + tempFile.getName() + "\">" + properties.getFile().getFilename() + "</a>");
getChildren().add(link);
} catch (IOException ex) {
Logger.getLogger(HtmlFormBuilderDownload.class.getName()).log(Level.SEVERE, null, ex);
}
}