Hi, I'm using this component with a button, it work well but I would like t

Hi,
I’m using this component with a button, it work well but I would like to use a confirm dialog before the download, to inform the user with a message, an if the user confirm with “yes” answer I would like to download the file and cancel action if user answers “no”.

Is it possible to do that ?

I’m using this example :

Button button = new Button("Click to download");
        FileDownloadWrapper buttonWrapper = new FileDownloadWrapper(
            new StreamResource("foo.txt", () -> new ByteArrayInputStream("foo".getBytes())));
        buttonWrapper.wrapComponent(button);
        add(buttonWrapper);

In that case, the wrapper should be on the button in the Dialog. The “click to download” button can be just a regular Button.

Hi Olli,

Thanks for your quick answer.
Could you please give me an example ?

I tried like this, but it doesn’t work :

    private void actionBtnEiv()
    {
        ConfirmDialog dialog = new ConfirmDialog("Confirmation",
                "Question ?",
                "Yes",
                event -> { },
                "No",
                event -> { });
        
        Button btnOK = UIUtils.createButton("Yes", ButtonVariant.LUMO_PRIMARY);
        btnOK.addThemeName("xsbutton");
        FileDownloadWrapper fileDownloadWrapper = new FileDownloadWrapper(new StreamResource("eiv.xml", () -> new ByteArrayInputStream(serviceRhCore.telechargerFichierEiv(transmission.getIdXML()))));
        fileDownloadWrapper.wrapComponent(btnOK);
        dialog.setConfirmButton(btnOK);
        dialog.open();
    }

You should use dialog.setConfirmButton(fileDownloadWrapper); instead of dialog.setConfirmButton(btnOK);.