uploadedFile在p:fileUpload中的bean中为null

时间:2016-09-23 07:55:09

标签: jsf primefaces upload

我在simpleMode中使用primefaces p:fileUpload。当我在前端上传任何文件时,我在bean端(后端)看到文件上传的null。您可以在下面看到示例代码。如果你能帮助我,我会很高兴的。

示例代码:

<h:form id="welcomeForm">
<p:fileUpload value="#{hashRaporBean.file}" mode="simple" />
<h:commandButton value="Submit" action="#{hashRaporBean.upload}" ajax="false" />
<h:message for="welcomeForm" />

Bean代码:

@ManagedBean(name = HashRaporBean.BEAN_NAME)
@ViewScoped
public class HashRaporBean implements Serializable {
private UploadedFile file;

public UploadedFile getFile() {
    return file;
}

public void setFile(UploadedFile file) {
    this.file = file;
}

public void upload() {
    if(file != null) {
        FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

1 个答案:

答案 0 :(得分:0)

我对h taglib不太了解, 可能是因为没有添加加密

<h:form id="welcomeForm" enctype="multipart/form-data" >

click here