我必须创建带附件的输入表单,所以我只想在提交按钮中执行文件上传,这样它就会将数据插入到数据库中并上传文件...我已经搜索过,我也没有找到任何文件简单的答案......提前谢谢 图片如下 http://i.stack.imgur.com/CX4dc.png
我试图在按钮中调用上传事件并禁用ajax但它失败了
<h:form enctype="multipart/form-data">
<p:panel header="Upload Files">
<p:fileUpload fileUploadListener="#{uploadbean.upload}"
update=":aform" allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx)$/" sizeLimit="30000000" />
</p:panel>
<p:commandButton ajax="false" action="#{uploadbean.upload}" value="Upload Files" />
</h:form>
答案 0 :(得分:0)
请查看Primeface的示例
<h:form enctype="multipart/form-data">
<p:messages showDetail="true"/>
<p:fileUpload value="#{fileUploadController.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false"
actionListener="#{fileUploadController.upload}"/>
</h:form>
你的bean中的:
public void upload() {
if(file != null) {
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
可从http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf获取。 你可以在“文件”部分的左侧边栏找到不同的文件上传器。 祝你好运