简体   繁体   English

Richfaces fileupload组件-文件上传事件之前

[英]Richfaces fileupload component - before file upload event

I am using Richfaces fileupload component to upload some files. 我正在使用Richfaces fileupload组件上传一些文件。 After I select a file, I would like to do something with the data, filename, etc before actually uploading the file. 选择文件后,我想对数据,文件名等进行一些操作,然后再实际上传文件。 However, I cant seem to find the the before upload event handler event handler. 但是,我似乎找不到上载之前的事件处理程序事件处理程序。

Question 1: What event is used to handle file selection -can I hook my code in there 问题1:使用什么事件来处理文件选择-我可以将代码挂在那里吗

Question 2: Is there an onbeforeUpload event? 问题2:是否存在onbeforeUpload事件?

Use the filesubmit event in your ajax listener: 在您的ajax侦听器中使用filesubmit事件:

<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" id="upload" acceptedTypes="jpg, gif, png, bmp"
            ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');" maxFilesQuantity="5">
            <a4j:ajax event="filesubmit" execute="@none" render="info" />
</rich:fileUpload>

The filesubmit event is fired before the file is upload 上传文件之前会触发filesubmit事件

Reference: 参考:

you can do any thing in the listner. 您可以在列表器中执行任何操作。

 public void listener(UploadEvent event) throws Exception{
    UploadItem item = event.getUploadItem();
    File file = new File();
    file.setLength(item.getData().length);
    file.setName(item.getFileName());
    file.setData(item.getData());
    files.add(file);

} 

use Primeface uploder . 使用Primeface升级程序 i think primeface is the best JSF framework. 我认为primeface是最好的JSF框架。

1) the component fires a "fileselect" event when you select a file. 1)当您选择文件时,组件会触发“ fileselect”事件。

2) not as such, but the component has "onbegin" attribute, you might be able to use that. 2)并非如此,但是组件具有“ onbegin”属性,您也许可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM