Download a file with DownloadLink or RequestHandler affects the functionality of the elements

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Download a file with DownloadLink or RequestHandler affects the functionality of the elements

lacribeiro11
Dear programmers,

my name is Luis, and at the moment I am having problems when downloading a file with wicket.
When I download a file it will affect the functionality of my check-box. It will not work right after I pressed download, I have to click in the check-box 2 times, so it will work again.

My code:
Checkbox:
CheckBox cbxWinners = new CheckBox("cbxWinners", Model.of(visible)) {
        private static final long serialVersionUID = 1L;
        @Override
        protected boolean wantOnSelectionChangedNotifications() {
                // This method works all the time, even if I had pressed download
                return true;
        }
        @Override
        protected void onSelectionChanged(Boolean newSelection) {
                /* After I pressed download, it didn't work right after. I had to press twice for it to work */
                visible = newSelection;

        }
};

When using Request in a link:
ResourceStreamRequestHandler target = new ResourceStreamRequestHandler(new StringResourceStream(“sometext”), "export.csv");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(target);

When using Donwloadlink:
DownloadLink downloadLink = new DownloadLink("export2", createFile(), "export.csv");
downloadLink.setDeleteAfterDownload(true);
downloadLink.onClick();

Tests where done for Request and Donwloadlink:
Test 1: Is a good tests
1. Open the download page, click the check-box 2 times => the method onSelectionChanged(Boolean newSelection) is called 2 times
2. Click download => the file is downloaded

Test 2: This test ends with the check-box not working correctly
1. Open the download page, click download => the file is downloaded
2. Click the check-box 2 times => the method onSelectionChanged(Boolean newSelection) is called only at the 2° time. But the method wantOnSelectionChangedNotifications() is called 2 times
I know that downloadLink.onClick() does a request as well.
My question is, if it is possible to download a file without affecting the functionality of the check-box?
With best regards,
Luis