opfau
opfau

Reputation: 761

Primefaces upload javascript callback when selected files changed

Is there a possiblity to have a callback in javascript or in the backing bean when the selected files in the primefaces upload has changed? Background: after the user has chosen the files he can define some attributes for each file. So I want to upload the files only if the has defined these attributes and clicked the save button. If all is uploaded and then the attributes are defined, I have to place the files somewhere on the server I think. The user must be able to select each file chosen for the upload to edit the attributes. There I need the chosen files after each changing.

I am using PF 5.2.6 and JSF 2.2.11.

Regards Oliver

Upvotes: 0

Views: 654

Answers (1)

opfau
opfau

Reputation: 761

At least I solved it with this javascript:

$(window).load(function() {
    var fileUpload = PF('docUploadWidgetVar');
    var filesAr = fileUpload.files;

    Object.observe(filesAr, function(changes){
        console.log('upload files array has changed');
        filesAr.forEach(function(file) {
            console.log(file.name);
        });
    });
});

For this HTML 5 is needed as I know. I am using the advanced and multiple primefaces upload which is required for this anyway as I know.

Upvotes: 0

Related Questions