【问题标题】:Finish uploading files and then execute the jsf:action of the button完成上传文件然后执行按钮的jsf:action
【发布时间】:2014-12-29 02:05:10
【问题描述】:

文件上传,如代码所示,调用一个方法,该方法将文件保存在一个列表中。从带有规则 PF('fileupload') upload() 的按钮上传文件; 我这里需要的是,当你上传预加载的“n”时,最近在上传结束时,执行按钮的action方法。

<p:fileUpload id="fileupload"
              widgetVar="fileupload"
              fileUploadListener="#{incidentBean.handleAttachment}"
              mode="advanced"
              label="Adjuntar (máx. 800kb)"
              invalidFileMessage="Archivo inválido"
              update="form-attachments"
              allowTypes="/(\.|\/)(jpg|jpeg|gif|png)$/"
              multiple="true"
              sizeLimit="820000"
              invalidSizeMessage="Archivo pesado" />

<button class="btn btn-info"
        type="submit"
        jsf:id="cmd"
        jsf:action="#{incidentBean.save()}"
        jsf:onclick="PF('fileupload').fileupload();">

感谢您的帮助。

【问题讨论】:

    标签: jsf file-upload primefaces upload


    【解决方案1】:

    您可以简单地将文件上传的oncomplete 属性连接到&lt;p:remoteCommand/&gt;,这样您将拥有:

      <p:remoteCommand name="save" actionListener="#{incidentBean.save}"/>
    

      <p:fileUpload id="fileupload" oncomplete="save();"  widgetVar="fileupload"/>
    

    【讨论】:

    • oncomplete 回调在文件上传请求之后执行。在多次上传的情况下,发出2次请求,oncomplete会执行两次。你必须改变 oncomplete="save();" for oncomplete="if(this.files.length == 0) save()"
    猜你喜欢
    • 2014-10-02
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 2021-07-23
    • 2020-07-15
    • 2015-09-20
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多