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