FileChooser

Hi
is there a way i can use a file chooser with vaadin?
The JFileChooser wants a java.awt.Component as a parent. But we are using only vaaind components.
Or the specific way, i want to add an Upload into a form. But the Upload isn’t a field and so it isn’t possible, and now i am looking for a possible solution to browse through my hard disk with a file chooser.

Thanks for your help

Aleksandar

When you are want to access the files in the client-side, Upload is the only option (as the access client-side is limited by browsers security model). Upload opens a native file chooser.

Here is a quick example on how to add Upload (or any component not implementing Field) to Form.


package com.example.uploadtest;

import java.io.OutputStream;

import com.vaadin.Application;
import com.vaadin.ui.Form;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Window;

public class UploadtestApplication extends Application {
    @Override
    public void init() {

        Form f = new Form();
        f.addField("name", new TextField("Name"));
        f.getLayout().addComponent(new Upload("CV", new Upload.Receiver() {

            public OutputStream receiveUpload(String filename, String MIMEType) {
                return null;
            }
        }));
        f.addField("country", new TextField("Country"));

        Window mainWindow = new Window("Uploadtest Application");
        mainWindow.addComponent(f);
        setMainWindow(mainWindow);
    }
}

Thanks a lot.
I will try to save the file temporarily and set a flag that these files are temporarily. And if the user leaves the window and wants to upload his files the files are unmarked and stored in a database.
But i have an other question. Is it possible to get access to the upload button? I want to make the invisible after the file was uploaded, and make him visible again if the user makes an interaction.

Greetz

You could make the whole upload component invisible - is this what you want?

Yeah this would be possible.
But i thought i can access only the upload button and replace it with an other button.
If there is a way please tell me if not i will try it with making the upload invisible.

Greetz

Hi !

This doesn’t work using a custom FormFieldFactory : the added component is displayed on top of the form. Any hint on this ?

Hi,

If you want to upload a filecontent to a value of a property (which I guess you want as you are using field factory), I really suggest to look at
EasyUploads
addon and especially its UploadField component. That should really simplify your task.

If you can’t upgrade to 6.5 nightly you can download the older version. For that I don’t promise to make any improvements though.

cheers,
matti


And do it in vaadin?