This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Vaadin and generic downloads in Portlets

Do you use a Vaadin application as portlet with e.g. Liferay and does your application create generic downloads (e.g. reports)?

If you want to download generic/dynamically created files from a portlet, you don't have too many options. You could use the FileDownloader extension or you could open a new window with the file resource. But both options are not perfect. The FileDownloader has to be connected to a clickable component e.g. a button and the new window won't be closed automatically (browser dependent). The FileDownloader is a good solution (see recommendations) but it triggers the download from the browser via user interaction. If you have dynamic UIs or if you can't use a FileDownloader because you need a more generic solution, then you could have a problem?

Our JVx Vaadin UI implementation is very dynamic and a developer doesn't use native vaadin components (until he needs to do). The FileDownloader didn't work for us because of UI abstraction. But we have a solution that might help you as well. Its comparable to FileDownloader but it's not user driven.

Simply use our extension with your UI:

//only once in init
DownloaderExtension downloader = new DownloaderExtension();
downloader.extend(this);

//start the download
downloader.setDownloadResource(resource);

The extension is not limited to UI but one Downloader per application is enough.

The source code is available in our repository.

10 Responses to “Vaadin and generic downloads in Portlets”

  1. Ronald says:

    Looks great, but i get this Exception:

    Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for com.sibvisions.rad.ui.vaadin.ext.ui.extension.DownloaderExtension. Check its component connector's @Connect mapping, ...

  2. rjahn says:

    Not sure what you did? Did you try to compile JVx.vaadin or did you add the source files to your own widgetset?

  3. Pierce Krouse says:

    I think he did what I did, which is just include the source in my source tree and instantiate the object in my UIs init() method. I am a Vaadin developer, but have only used the standard server-side components until now. There must be some other step involved in using this that first-time widget users are not aware of.

    I say that because in your reply you mention JVx.vaadin and adding source files to my widget set, and I don't understand either of those statements. I know my project has a .gwt.xml file that defines my (empty) widgetset, and I have added jar file references to that file with an inherits line, but my knowledge ends there. I will try and solve my problem by the usual google searches, but the widgetset tutorials I have found go into things like connectors and so on, and I suspect that just doesn't apply here. I need to get my feet wet a little more slowly.

  4. rjahn says:

    I see. I'll prepare a small example project for you, tomorrow.

  5. Pierce Krouse says:

    Thanks rjahn, that would be very helpful!

  6. rjahn says:

    No problem... I'll post an update asap.

  7. rjahn says:

    A zip archive with a complete Eclipse project and demo application is available here. Simply import the project and deploy it.

    The application is a standard Vaadin 7.3.5 application, created with Vaadin Eclipse plugin - no magic!
    The DownloaderExtension was copied from JVx.vaadin and widgetset was created with Eclipse plugin - no extra ant file.

    I hope it'll help :)

  8. Pierce Krouse says:

    Wonderful example rjahn, thanks for your help! I see how the extensions and connectors work now, and your example runs perfectly in IE, ffox and chrome.

    Is there some reason that this extension would be sensitive to file types or file extensions? The ContactsForm.xls downloads properly, but when I add a PNG file in the same location (com.example.vaadinjvxset) and duplicate the ContactsForm code to another button and listener, the download doesn't work. There are no errors on my console, just no action in the browser for the PNG file I put in there.

  9. rjahn says:

    You're right! The example source was copied from JVx VaadinUI and it has an option to show or save the content. I simply forgot to copy one method :)

    I've changed the example for you - download.

  10. Pierce Krouse says:

    Thanks rjahn, that works with all file extensions I can throw at it for now. I really appreciate all your help on this!

Leave a Reply

Spam protection by WP Captcha-Free