我在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);
}
}
答案 0 :(得分:0)