.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]