2016-03-29 210 views
0

Vaadin非常非常新。通過研究Github和其他文檔,我正在使用Spring-security,Vaadin,Maven來設置項目。文件上傳和下載vaadin

我用spring安全項目創建了樣本vaadin-maven。現在我得到登錄頁面,然後在suucessful登錄後,得到一些MainView.java。

我正在嘗試更改上傳的.xls文件並讀取該文件並執行一些功能,然後下載彈出窗口。

我按照http://demo.vaadin.com/sampler/#ui/data-input/other/upload,但錯誤。無法重現我的輸出。現在,我能夠使用路徑讀取文件「final String FILE_PATH =」F://input.xls「;」但是,我需要選擇上傳文件,然後使用該文件獲得更多功能。

功能完成後,我需要下載該文件。

請建議我如何瀏覽文件並上傳並使用上傳的文件進行一些讀寫操作,然後下載Vaadin。

我已經不眠之夜了。請建議我怎樣才能出來這個。 這是我的代碼:

@Component 
@Scope("prototype") 
@VaadinView(RoleAdminView.NAME) 
@Secured("ROLE_ADMIN") 
public class RoleAdminView extends Panel implements View 
{ 
    public static final String NAME = "role_admin"; 

@PostConstruct 
public void PostConstruct() 
{ 
    LoggerFactory.getLogger(this.getClass()).debug("POST"); 
    setSizeFull(); 
    VerticalLayout layout = new VerticalLayout(); 
    layout.setSpacing(true); 
    layout.setMargin(true); 
    layout.addComponent(new Button()); 
    layout.addComponent(new Label("ROLE_ADMIN")); 
    layout.addComponent(new Link("Go back", new ExternalResource("#!" + 
    MainView.NAME))); 

    setContent(layout); 
    } 

    @Override 
    public void enter(ViewChangeListener.ViewChangeEvent event) 
     { 
    } 
    } 

非常感謝您提前。希望你們理清我的問題:)

+0

請出示您的用於處理上傳的代碼。您將需要存儲文件serverside進行處理。如果它在內存中或臨時文件取決於您的要求 –

+0

感謝您的回覆@AndréSchild。我不知道如何處理vaadin中的上傳文件。我剛剛創建了root.addComponent(new upload());.我卡在這裏。我無法進一步移動:( – user3599302

+0

http://demo.vaadin.com/sampler/#ui/data-input/other/upload我使用了源代碼並添加了代碼,在lineBreaker上出現錯誤,等等。我不知道如何移動,請讓我的一天免費@AndréSchild:( – user3599302

回答

1

你可以做,

public class RoleAdminView extends Panel implements View{ 

//add a button view 
// 
    @Override 
public void uploadFailed(Upload.FailedEvent event) { 
    Notification.show(event.getFilename() + "----" + event.getMIMEType()); 
    //here it will show the error if upload failed 
} 

@Override 
public void uploadSucceeded(SucceededEvent event) { 
/// do your functionlity 
} 
    @Override 
public OutputStream receiveUpload(String filename, String mimeType) { 
    FileOutputStream fos = null; 
    // do your functionality to save in any path or server path 
    return fos; // Return the output stream to write to 
} 

} 

我希望這是我對您有幫助:)

+0

謝謝...我會檢查與此... :) – user3599302