我尝试在 p:dialog 中使用 PrimeFaces p:fileUpload 上传文件,但不起作用
<h:form id="form3">
<p:commandLink value="upload" oncomplete="PF('Dialog').show()" />
<p:dialog widgetVar="submitDialog" modal="true" >
<h:form id="form" enctype="multipart/form-data" >
<h:panelGrid id="submitPanelGrid" columns="2" >
<p:fileUpload id="upload" value="#{bean.file}" mode="simple" sizeLimit="100000" />
<p:commandButton id="btn3" action="#{bean.submit()}" icon="ui-icon-circle-check" ajax="false" />
</h:panelGrid>
</p:panel>
</h:form>
</p:dialog>
</h:form>
点击链接后,我收到此异常:
org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream,
content type header is application/x-www-form-urlencoded;
但在外面<p:dialog>
,效果很好。
最佳答案
首先,html中不允许在另一个表单中使用另一个表单,您必须将对话框与主表单分开,对于您遇到的异常(exception)情况,您必须添加 enctype="multipart/form-data"
到您的对话框表单:
<h:form id="form3">
<p:commandLink value="upload" oncomplete="PF('Dialog').show()" />
</h:form>
<p:dialog widgetVar="submitDialog" modal="true" >
<h:form id="form" enctype="multipart/form-data" >
<h:panelGrid id="submitPanelGrid" columns="2" >
<p:fileUpload id="upload" value="#{bean.file}" mode="simple" sizeLimit="100000" />
<p:commandButton id="btn3" action="#{bean.submit()}" icon="ui-icon-circle-check" ajax="false" />
</h:panelGrid>
</p:panel>
</h:form>
</p:dialog>
关于jsf - p :fileUpload doesn't work inside p:dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46187020/