我尝试在 GXT 中制作一个表单来上传文件,但我在网上看到了更多示例,我未能使其成为一个简单的 FileUploadField 来在本地保存文件。
Cde片段:
formPanel = new FormPanel();
formPanel.setBodyBorder(false);
formPanel.setHeaderVisible(false);
formPanel.setAction(GWT.getModuleBaseURL() + "fileUpload");
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formPanel.setHeaderVisible(true);
fileUploadField = new FileUploadField();
fileUploadField.setName("fileName");
fileUploadField.setAllowBlank(false);
fileUploadField.setFieldLabel("Archivo");
fileUploadField.addListener(Events.OnChange, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent BaseEvent) {
aSubmitButton.setEnabled(true);
}
});
aSubmitButton = new Button("OK");
aSubmitButton.setEnabled(false);
aSubmitButton.setId("submit_button");
aSubmitButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent inButtonEvent) {
formPanel.submit();
}
});
上面的代码是FormPanel和FileUploadField的声明。