【问题标题】:Advanced fileUpload get the file null with Primefaces [duplicate]高级fileUpload使用Primefaces获取文件null [重复]
【发布时间】:2017-07-31 10:02:19
【问题描述】:

环境:

  • Primefaces 6.1
  • JavaEE 7
  • 野蝇 10
  • JSF 2.2

当我在选择文件后单击按钮时,文件 var 为空。

Test.xhtml

<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
        <h:head>
            <title>Application</title>
        </h:head>

        <h:body>

            <h:form id="frmTest" enctype="multipart/form-data">
                <ui:include src="template/messages.xhtml" />
                <p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false"
       update="messages" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
            </h:form>
        </h:body>
    </f:view>
</html>

TestBean.java

@ViewScoped
@ManagedBean
public class TestBean implements Serializable {
...
public void handleFileUpload(FileUploadEvent event) {
        UploadedFile file = event.getFile();//file is null
        FacesUtils.addInfoMessage("Succesful" + file.getFileName() + " is uploaded.");
        System.out.println("Succesful" + event.getFile().getFileName() + " is uploaded.");
}
...

【问题讨论】:

  • 您是否已经按照stackoverflow.com/questions/8875818/… 中的说明查看了&lt;h:form enctype="multipart/form-data"&gt;?
  • 是的,我已经在 stackoverflow 中遇到过这个问题,但没有任何效果。该事件甚至没有被调用。

标签: jsf file-upload primefaces


【解决方案1】:

您应该从fileUpload 组件中删除或填充update="" 属性。它在上传后将文件“重定向”到组件。

【讨论】:

  • 我测试了它也没有工作。
猜你喜欢
  • 1970-01-01
  • 2013-06-06
  • 2015-08-05
  • 2015-08-28
  • 1970-01-01
  • 1970-01-01
  • 2013-08-29
  • 2014-08-23
  • 1970-01-01
相关资源
最近更新 更多