How can I invoke the Upload widget from a MenuItem?
The Basic MenuBar demo shows how to capture the “File Open” menu item action. The Single-Click Upload demo shows how to pop up a file selection dialog. I would like the menu item action to pop up the file selection dialog. So far I have only been able to accomplish this through a two step process: the file-open menu item pops up the Upload widget, then the user needs to click the “select file” button on the widget. I would like the “select file” button to be invoked immediately through the File-Open menu action.
Thanks
EDIT
So perhaps the menu command needs to invoke some javascript directly as attempted below? But it isn’t quite right. Thing is, File - Open File is even part of the basic menubar demo, so I would think there must be a way to do this, but the sample stops before actually doing the action.
private Command uploadCommand = new Command() {
@Override
public void menuSelected(MenuItem selectedItem) {
String fileUploadDiv = "<div><form id='fileForm'><input type='file' id='theFileId' name='uploadFile'/></form></div>";
try {
CustomLayout cl = new CustomLayout(new ByteArrayInputStream(fileUploadDiv.getBytes()));
getWindow().addComponent(cl);
getWindow().executeJavaScript("document.getElementById('theFileId').focus().click();");
} catch (IOException ex) {
}
getWindow().showNotification("Upload Invoked");
}
};