Click listener in Anchor

Hi all,
I have an Anchor that downloads a generated file. The problem is that when I try to add an event listener for a click to close the dialog that the Anchor is in, the link to the download doesn’t work.

download = new Anchor(changeLogService.generateChangeLog(project, version, fixed, added, changed, user), "Descargar");
download.getElement().addEventListener("click", event -> {
	zipDialog.close();
});

Is there a way to do this?

Anchor seems to lack specific addClickListener so you should use the addEventListener according to this documentation, and that is what you are doing.

https://vaadin.com/docs/v10/flow/element-api/tutorial-event-listener.html

There is another discussion about it here and reported working with I assume different component

https://vaadin.com/forum/thread/17088333

I recommend to add logging to check if the event is caught but problem is in closing instead.

And if it is really not working, bug should be reported here: https://github.com/vaadin/flow/issues

Hello Tatu Lund,
it is going into the click listener and using the close() method, but the link for the download of the file is generating this error:

HTTP ERROR 404
Problem accessing /VAADIN/dynamic/resource/0/c1cd5f84-d00d-4cf4-8330-b1b24add6220/Changelog.zip. Reason:

    Resource is not found for path=VAADIN/dynamic/resource/0/c1cd5f84-d00d-4cf4-8330-b1b24add6220/Changelog.zip
Powered by Jetty:// 9.4.11.v20180605

However, if I run the code in Debug mode and I stop in the click listener, it works. I think the problem is that the click event is executing before generating StreamResource and when the href is opened the anchor doesn’t exist because the dialog, that contains the anchor, has been closed.