Hi,
I am new to Vaadin 10. My requirement is to disable the “Button (in my case, downloadLogsButton)” asynchronously. Please find below more details and the code.
-
As per requirement, Button (downloadLogsButton) is wrapped in Anchor (downloadFile).
-
After the click on Anchor (downloadFile), the data gets fetched from the database. It is during this time, while the data is getting fetched from the database, I want the button (downloadLogsButton) to be disabled.
-
After the data is fetched and file is downloaded, I want the button to be enabled again.
-
I have put the @Push at the main file.
-
Tried the below syntax which is not working. The button gets disabled after the data is fetched and the file is downloaded.
Please help and provide solution.
Code Snippet:-
Anchor downloadFile = new Anchor(new StreamResource(orderNumber + "_logs.txt", () -> {
// Push is not working
ui.access(() -> {
downloadLogsButton.setEnabled(false);
ui.push();
});
// Code to generate the logs file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteArrayOutputStream);
try {
// Fetch the required data
String xmlResponse = getDataFromDatabase();
out.writeBytes(xmlResponse);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
}), "");
downloadFile.getElement().setAttribute("download", true);
downloadFile.add(downloadLogsButton);
downloadLogsLayout.get().add(downloadFile);
Thanks