Save File Dialog

Do we have a save File Dialog in vaadin? It looks like Upload has it inbuilt but I am not trying to upload anything so I can’t use it. I just need to have a save-as option and get a file name and location from the user in a client/server environment.

Can anyone guide me? I am new to vaadin and java.

thanks,

maybe this will help you:

Button saveBtn = new Button("Save");
saveBtn.addListener(new ClickListener() {

    @Override
    public void buttonClick(ClickEvent event) {
        StreamSource ss = new StreamSource() {
            InputStream is = new ByteArrayInputStream("some silly text content".getBytes());
            @Override
            public InputStream getStream() {
                return is;
            }
        };
        StreamResource sr = new StreamResource(ss, "export", YourApplicationInstance);
        getMainWindow().open(sr, "_blank");
    }

});

imo you wont be able to directly save the file to the users disk out of your java code, that would be a huge security lack…

there is also a FileResource btw, maybe this is even better

Thanks for the reply.

I am trying to save some data in a file in user’s machine. I have a browse button and when I click it I want to show a FileSave Dialog and prompt the user to type in a file name.

Any suggestions??

Thanks!!!

To save something to the user’s machine you can only just provide a file to download like any other web site. For that you can use Felix’s suggestion. If you want you could make a pop-up or just a field asking for a file name before sending the download stream, but other than that it is the same thing. Where the file goes depends mostly on the browser. Some ask for a folder where to put it but most just put them into a common downloads folder.

If you are using GAE, this might not work for you.
I haven’t tested it yet, but I think you should save a blob and then serve it.
More info here:

http://code.google.com/appengine/docs/java/blobstore/overview.html#Serving_a_Blob

UPDATE: I recently used this approach and wrote something about it in this post:
http://beansgocrazy.blogspot.com/2011/11/serving-files-in-gae.html