Good day all, I would like to know if someone can help me establish the following: I have a grid with a form. Every time I save the form, it creates a new row with the values from the form. What I want now, is a download button on every row, to download the content of the selected row and put it in a text file. So in the end, I'll be able to download a .txt file with contents of the selected row.
I'm using Vaadin 10
Please help.
What I would like to get
document id attchfilename download
1 xxx download
2 yyy download
This below is what I've already tried, but I would like to do it with a download button.
Anchor anchor = new Anchor(getStreamResource("default.txt", "default content"), "click me to download");
anchor.getElement().setAttribute("download",true);
textField.addValueChangeListener(e -> {
anchor.setHref(getStreamResource(textField.getValue() + ".txt", textField.getValue()));
});
public StreamResource getStreamResource(String filename, String content) {
return new StreamResource(filename,
() -> new ByteArrayInputStream(content.getBytes()));
}