【问题标题】:p:fileUpload doesn't work inside p:dialogp:fileUpload 在 p:dialog 中不起作用
【发布时间】:2018-02-21 13:03:30
【问题描述】:

我正在尝试在 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:请求不包含 multipart/form-data 或 multipart/mixed 流,
内容类型标头为 application/x-www-form-urlencoded;

但是在&lt;p:dialog&gt;之外,它工作得很好。

【问题讨论】:

  • 您是否尝试在表单中指定多部分?例如:
  • 是的,我试过了,但没用
  • html(和 jsf)中不允许嵌套表单

标签: jsf file-upload primefaces dialog


【解决方案1】:

首先,在 html 中不允许将一个表单放在另一个表单中,您必须将对话框与主表单分开,对于您遇到的异常情况,您必须将 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>

【讨论】:

  • 将 'Dialog' 更改为 'submitDialog',因为 PF 必须引用 widgetVar。
猜你喜欢
  • 2013-05-16
  • 2013-06-28
  • 2015-02-21
  • 2013-09-28
  • 2017-01-02
  • 1970-01-01
  • 1970-01-01
  • 2017-10-31
  • 1970-01-01
相关资源
最近更新 更多