Link FileResource- Getting data from a web service


I have a webservice that provides me a file data as byte array. Also I have a grid layout that have a set of links in each row, and I use the web service to set each of the links’ FileResource.

Here is some relevant code:

//Overriden Link component
FlexLink link = new FlexLink(kbsArsiv.getDosyaAdi(), null);

//Here is where I call the webservice. It is wrapped by a Spring service.
					DownloadFileResult downloadFileResult = repositoryService.downloadFile(kbsArsiv.getId().toString());

					if (downloadFileResult.isSuccess()) {

//downloadFileResult.getDataHandler() gives me byte[] of the file that I want to download. I convert byte[]
 to a file object.
File file = convertByteArrayToFile(downloadFileResult.getDataHandler());

//And I set the file resource.
						final FlexFileResource fileResource = new FlexFileResource(file, FlexCityApplication.get());


The above code is in a for loop, so this runs for each row on my grid, so that for each link, I can set the resource I want. However the problem here is, when repositoryService.downloadFile() has an internal exception that I catch and show as a humanized message alert, It shows that error when the links are not clicked already.

So I actually don’t want to set FileResources in the loop. I want to set the resource to links just before the click for downloading. When I click it should set the resource and then do its job. I cannot handle the click function in Link. If I use a Button with a style of a link instead of a link, I can not set any resource to it(of course).

Here is my code in, the downloadFile method:

public DownloadFileResult downloadFile(String kbsArsivId) {
		DownloadFileResult downloadFileResult = null;
		try {
			downloadFileResult = archiveAccessProxy.downloadFile(repUser, repPassword, "", "", kbsArsivId);
		} catch (RemoteException e) {
//here is the exception that I handle from UI
			throw new FlexCitySystemException(e);
		return downloadFileResult;

So, for short, the resources are now set to the links on page create, and if there is a problem with the service, users get the error message for download service, and says “I dont even clicked on the link!!”

How can I set the resource when the user clicks on the link?

Any help?

Couldn’t you use a normal Button, create the FlexFileResource in the ClickListener, then call

As another alternative, you could create a simple (non-vaadin) servlet that just handles downloding the file based on the id, and then create a normal link that links to the url.



As I said in the post before normal Button usage had come to my mind, but I thought there was no usage of a Resource with a Button. However your recommandation about passing a Resource parameter to a Window’s open() method resolves my problem.

So thnx very much Charles,