簡體   English   中英

PrimeFaces 3.2簡單的FileUpload,在上傳之前獲取所選文件信息,如文件名

[英]PrimeFaces 3.2 simple FileUpload , Get selected file Info like file name before upload

我正在使用(Java Server Faces 2.2)Primefaces 3.2簡單文件上傳控制器。 我需要在上傳之前訪問文件信息。 選擇文件時我可以使用什么監聽器?如何在啟動上載之前在ManagedBean獲取文件信息

attribute of that fires when upload starts. 標記不支持任何ajax行為事件,因此您唯一能做的就是在上傳開始之前使用該屬性調用方法。 使用遠程命令,您可以執行以下操作:

<p:remoteCommand name="beforeUpdate" partialSubmit="true" process="@this" 
                                 actionListener="#{myBean.doBefore}" value="" />

將對遠程命令的調用添加到fileUpload

<p:fileUpload fileUploadListener="#{itemImportDialogController.uploadListener}" 
         mode="advanced" multiple="true" onstart="beforeUpdate()"
         styleClass="importItems" update=":itemImportView:fileForm" style="margin: 10px 0"/>

並在bean中添加這樣的方法

public void doBefore() {
     //DO SOME WORK
}

關於文件名,只有在上傳文件時才能檢索它

public void uploadListener(FileUploadEvent event) {

    UploadedFile file = event.getFile();
    //DO SOMETHING
}

因為在此之前組件和服務器之間不存在ajax交互。 所以我很抱歉,但不可能。

順便說一下,你可以嘗試通過jQuery捕獲事件來管理這個

$('input[type=file]').change(function() { 
    //GET THE FILE AND SUBMIT IT TO THE SERVER WITH AJAX CALL 
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM