Thursday, December 15, 2011

Wicket DownoadLink and AjaxDownload with non-ascii filenames

The problem - yet unsolved for me :(

You have an Apache Wicket application (in my case, this is wicket 1.4.x). You have a page which asks user to download some content and then lets download it. Content is dynamically generated (file?). It should have a name (default one) on client's machine. Name may have cyrillic (or Chinese) symbols.

First of all, I was unable to solve this completely :(

Coming from StackOverflow post, the good way to do would be to form the URL ending with a filename (URL-encoded), and show no filename in Content-Disposition header. All other tricks and tips work not well under different browsers.

Wicket usual approach is to use either DownloadLink or AjaxDownload (thank you guys for such a good solution! Liked it much). First of them is using usual wicket URL coding strategy and second - pretty much the same, being a AjaxBehavior and thus IBehaviorListener. That far I could see no real way to change these URLs. The issue is that both of those don't allow for custom URLs, they are actually plugged into Wicket's infrastructure of page-component-iBehaviorListener-RequestCycle-RequestCodingStrategy chain, so we don't have direct control over it.

One solution proposed by Martin Grigorov on the wicket-users mailing list was to use for mounting, but that did not work out for me as I needed to use containing page's model to generate the actual data.

Fail :(
Will up if any luck.

No comments: