简体   繁体   中英

PrimeFaces 8 <p:fileUpload> does not work in the same way as in PrimeFaces 7

I recently migrated from PrimeFaces 7 to PrimeFaces 8, but the <p:fileUpload component does not work as expected in PrimeFaces 8. Here is the minimal example:

My facelet:

<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:p="http://primefaces.org/ui"
          lang="en">

          <h:head>
           <f:facet name="first">
               <meta http-equiv="X-UA-Compatible" content="IE=edge" />
               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
               <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
               <meta name="apple-mobile-web-app-capable" content="yes" />
           </f:facet>
          </h:head>
          <h:body>
                <h:outputStylesheet name="primeicons/primeicons.css" library="primefaces"/>

                <div class="ui-g ui-fluid"> 
                    <div class="card card-w-title">
                        <h:form id="inseratForm" enctype="multipart/form-data">  
                                <div class="card-title">Objekt anlegen</div> 
                                <p:growl id="messages" autoUpdate="true" showDetail="true" />  
                                <p:fileUpload 
                                        fileUploadListener="#{objAnlBean.handleFileUpload}"
                                        label="Select images" 
                                        auto="true"
                                        multiple="true"
                                        dragDropSupport="true"
                                        sizeLimit="100000000" 
                                        invalidSizeMessage=""
                                        invalidFileMessage="Invalid File"
                                        fileLimitMessage=""
                                        validatorMessage="Invalid File Type"
                                        showButtons="false"
                                        update="@form:uploadedImagesDiv"
                                        allowTypes="/(\.|\/)(gif|jpe?g|png)$/i">

                                        Upload Images

                                     <h:panelGroup id="uploadedImagesDiv" layout="block"/>
                                 </p:fileUpload>
                         </h:form>
                    </div>
                </div>      
        </h:body>
       </html>

The Backing Bean:

import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

@Named("objAnlBean")
@javax.faces.view.ViewScoped
public class ObjAnlBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public void handleFileUpload(FileUploadEvent event) {
        UploadedFile uploadedFile = event.getFile();
        String fileName = uploadedFile.getFileName();
        String contentType = uploadedFile.getContentType();
        System.out.println("fileName = " + fileName + ";contentType =  " + contentType);
    }
}

My expectation is that whenever I put a breakpoint in the handleFileUpload() method and I try to upload file(s) from the front-end, the handleFileUpload() method is called. This works as expected in PrimeFaces 7, but not in PrimeFaces 8.

Please help!

Thanks to the guys in the comments below!

fileUploadListener attribute of the <p:fileUpload is renamed in PrimeFaces 8 to just listener

This change is apparently also documented in the Migration Guide. With that, the question is solved / closed.

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