Hi Nikolay I tried SimpleFileDownload with a simple test code, but when I click on button nothing happens.
final SimpleFileDownloader downloader = new SimpleFileDownloader();
addExtension(downloader);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
final StreamResource resource = new StreamResource(new StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream("This is test clicked on button".getBytes());
}
}, "testButton.txt");
downloader.setFileDownloadResource(resource);
downloader.download();
}
});
myLayout.addComponent(button);
I’ve resolved. The problem was Ivy, after ivy caches clean now works.
But I’ve another question: using Page.getCurrent().open(resource, filename, true) the browser let the user to select action: save or open (the file is a pdf), but with SimpleFileDownloader there is only save option.
Can I use SimpleFileDownloader in that way?
I am supper newbe to this framework and been given a task to work on few tasks out of which downlaoding the table content by selecting a variouse format via Combobox like xls, csv, geojson which is json text file, .dat file. I tried to use CSVExporter(tablecontent); and get the object to dawnload. but I wasnt able to ;(. any idea or similar work would be greatly appreciated. here is my code snippit,
I tested your example on version 2.0.2 and it works fine. Probably something wrong with file (permissions or it’s not exist at the moment when you trying to download it).
.hi. i am trying to set file name dynamically in a FileDownloader. i’v done this:[code]
StreamResource myResource = createResource();
FileDownloader downloader = new FileDownloader(myResource)
{ @Override
public boolean handleConnectorRequest(VaadinRequest request , VaadinResponse response , String path)
throws IOException{
myResource.setFileName(“new.txt”);
return super
.handleConnectorRequest(request,response,path);
}
};
Button dounloadButton = new Button(“Download Button”);
downloader.extend(downloadButton);
private StreamResource createResource(){
return new StreamResource(new StreamSource()
{ @Override
public InputStream getStream(){
File file = new File(“test.txt”);
try{
But the handleConnectorRequest method was not called.I do not how this method works and what should i do to call that? I’m new to everything! so if my question is obscure, let me know(give me comment).
I’ve tried to setup SimpleFileDownloader but nothing happens for me too. That being said I had to remove the line
addExtention(
Your method addExtension is linked to what Object? I ask because I have a static method that handles the mouse click and so it won’t compile because addExtension has to be linked to some kind of class…
It’s not on the Layout, the Button, etc., so what object addExtension in? That’s the only line I can’t seem to add anywhere…
Please do not call it from a click listner method. Create the FileDownloader object when you create the button itself and extend the filedownloder object with button created. Next time when u click the buttion everything will work fine. Hope this helps. I struggled alot with this finally found this solution
[code]
Button runReportBtn = new Button(PageConst.RUN_REPORT_CAPTION);
FileDownloader downloader = new FileDownloader(new StreamResource(
new StreamResource.StreamSource() {
private static final long serialVersionUID = 423966284085861068L;
@Override
public InputStream getStream() {
// Your method which will provide the input stream.
}
},"PDF_"+System.currentTimeMillis()+".pdf"));
downloader.extend(runReportBtn);
hLayout.addComponent(runReportBtn);
[/code]