Amira
Amira

Reputation: 3270

Refreshing a drop-down list after adding a new item

I'm new to Vaadin and i want to implement this : a A drop-down list containing file names for single selection. and an upload file button , after uploading a file the file name is added to the drop-down list :

 List <String> fileDirList = Utilities.getDirectoryList("/home/amira/runtime/uploads/report");

  // Create a selection component
  Select select = new Select ("Select file");

   for (String fileName : fileDirList) {

      select.addItem(fileName);
    }

   public void uploadSucceeded(SucceededEvent event) {

        String userHome = System.getProperty( "user.home" );
        String filename = event.getFilename();


            // Open the file for writing.
            file = new File(userHome+"/runtime/uploads/report/"+filename);
            String fileName = filename.substring(0,filename.length()-4 );
            fileDirList.add(fileName);



    }
};

The problem that the drop-list is not updated after uploading the file and adding its name in the fileDirList . So how to refresh it

Upvotes: 0

Views: 223

Answers (1)

nexus
nexus

Reputation: 2937

When you add an object to your fileDirList the select component doesn't recognize this, because there is no connection between them.

You could create a method which adds the filename to the select component and to the list:

private void addFilename(String sFilename) {
     fileDirList.add(sFilename);
     select.addItem(sFilename);
}

Invoke this method in your upload code.

Upvotes: 1

Related Questions