[英]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.