p:fileUpload不在p:dialog

时间:2017-09-13 00:19:41

标签: jsf file-upload primefaces dialog

我试图在p:对话框中使用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;

但在<p:dialog>之外,它运作得很好。

1 个答案:

答案 0 :(得分: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>