Hi everyone,
I am struggling with the FileDownloader and how to make my download working.
The WebUI I have build now contains a button. When someone click the button, a new Thread will start to create the file.
the following code does not work, as the FileDownloader will throw a nullpointer exception as the file does not exist at the time I press the button:
btn_start.addClickListener(e -> {
CompletableFuture<PDF> workThread = pdf.create();
workThread.thenRunAsync(() -> {
try {
pdfFile = workThread.get();
System.out.println("++++" + pdfFile.getName());
} catch (Exception e1) {
e1.printStackTrace();
}
access(new Runnable() {
public void run() {
btn_start.setVisible(true);
progressWindows.close();
}
});
});
});
fileDownloader = new FileDownloader(new FileResource(pdfFile));
fileDownloader.extend(btn_start);
So new Idea was, to create a new button in the click event and assign the FileDownloader to a hidden Button.
The click on the hidden buttun is executed, but doenload still does not start.
But also I do not get a nullpointer anymore, so it seems like the file is found.
btn_start.addClickListener(e -> {
CompletableFuture<PDF> workThread = pdf.create();
workThread.thenRunAsync(() -> {
try {
pdfFile = workThread.get();
System.out.println("++++" + pdfFile.getName());
} catch (Exception e1) {
e1.printStackTrace();
}
access(new Runnable() {
public void run() {
btn_start.setVisible(true);
progressWindows.close();
ClickListener click = new ClickListener() {
private Thread searchThread;
@Override
public void buttonClick(ClickEvent event) {
searchThread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Click working");
}
});
searchThread.start();
}
};
new_Button.addClickListener(click);
click.buttonClick( new ClickEvent(new_Button) );
}
});
});
});
fileDownloader = new FileDownloader(new FileResource(pdfFile));
fileDownloader.extend(new_Button);
What is the best way to get the FileDownloader running when the file does not exist before the click?
Any help would be really appriciated.