Question

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?

Was it helpful?

Solution

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:

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top