Asynchronous Updates - DISABLE THE BUTTON - VAADIN 10

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.

  1. As per requirement, Button (downloadLogsButton) is wrapped in Anchor (downloadFile).

  2. 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.

  3. After the data is fetched and file is downloaded, I want the button to be enabled again.

  4. I have put the @Push at the main file.

  5. 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

Any updates on this. Kindly provide your suggestions. Thanks.

Did you ever solve this? I’m facing the same type of issue and have been banging my head on this.

Not solved yet. I am still looking for a solution and response from Vaadin team.