Validating user input before starting download

I have a button/anchor to download files as described in Download button in Vaadin 24.9 - Vaadin Forum.

Follow-up question: what if I need do something before initiating the download, e. g. validating some input data?
Where do I put this? In the anchor’s DownloadEvent handler? In the button’s ClickEvent handler? Or somewhere completely different?