简体   繁体   中英

Richfaces fileupload component - before file upload event

I am using Richfaces fileupload component to upload some files. 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

Question 2: Is there an onbeforeUpload event?

Use the filesubmit event in your ajax listener:

<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

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 . i think primeface is the best JSF framework.

1) the component fires a "fileselect" event when you select a file.

2) not as such, but the component has "onbegin" attribute, you might be able to use that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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