Primefaces Fileupload: Display question dialogue that influences upload behaviour

Viewed 19

I am using the Primefaces Fileupload component (Primefaces V.6.2.17) to upload files like this:

upload.xhtml:

<p:fileUpload fileUploadListener="#{uploadView.handleFileUpload}" id="fUpload"
   mode="advanced" dragDropSupport="true" multiple="true"
   widgetVar="fUploadWid" auto="true" sequential="true" />

uploadView.java:

public void handleFileUpload(FileUploadEvent event)  {
   //handle fileupload
}

Now I would like to change it so that when the user tries to upload a file, instead of directly calling the handleFileUpload() method, I want it to display a dialog where the user can pick between two upload-modes. Ideally, this would result in either a method handleFileUploadModeA() or a method handleFileUploadModeB() being called.

How can I do that / is this possible with my Primefaces version?

1 Answers

No you can't. In later version of PF like PF11+ they added onupload but you can only ask a question which returns a boolean either proceed with the upload or cancel see the example here in the showcase: https://www.primefaces.org/showcase/ui/file/upload/single.xhtml

<h:form enctype="multipart/form-data">
        <p:fileUpload listener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false"
                      update="messages" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                      validateContentType="true" accept=".gif,.jpg,.jpeg,.png"
                      onupload="return confirm('Are you sure?')"/>

        <p:growl id="messages" showDetail="true"/>
</h:form>
Related