primeFaces 8 fileUpload 组件的 fileUploadListener 不起作用



我最近从PrimeFaces 7迁移到PrimeFaces 8,但是p:fileUpload组件在PrimeFaces 8中没有按预期工作。下面是一个最小示例:

我的脸:

<!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>

背豆:

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);
}
}


我的期望是,每当我在handleFileUpload((方法中放置断点并尝试从前端上传文件时,都会调用handleFileUpload((方法。这在PrimeFaces 7中按预期工作,但在PrimeFaces 8中则不然。

p:fileUploadfileUploadListener属性在PrimeFaces 8中重命名为仅listener

迁移指南中也记录了此更改。

相关内容

  • 没有找到相关文章

最新更新