如何使用<h:inputfile>?</h:inputfile>对完成的上传做出反应

时间:2014-01-27 09:17:04

标签: file-upload richfaces ajax4jsf jsf-2.2 wildfly

我在Wildfly-8.0.0.CR1上使用Richfaces-4.3.5,从<rich:fileUpload>迁移,但不适用于JSF-2.2 / Servlet-3.0。我正在用这个片段替换它:

<rich:popupPanel id="testPop" autosized="true">
    <h:form id="uploadF" enctype="multipart/form-data">
       <h:inputFile value="#{bean.file}">
           <a4j:ajax listener="#{bean.storeFile()}" render="@form,:fileListTbl"
               oncomplete="#{rich:component('testPop')}.hide();" />
       </h:inputFile>
    </h:form>
</rich:popupPanel>

这样可以正常调用storeFile方法,我可以正常访问bean.file。但是,当我完成上传时,我想关闭rich:popupPanel,所以我需要对ajax请求的成功/完成事件做出反应。但这似乎不太可能 - 弹出窗口仍然可见,响应显然不完整(缩进以提高可读性):

<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1">
  <changes>
    <update id="j_id1:javax.faces.ViewState:0">
      <[CDATA[-1186354868983349335:-5499969782208038164]]>
    </update>
    <extension id="org.richfaces.extension"><render>@component</render></extension>
  </changes>
</partial-response>

虽然richfaces调试消息表明正在调用处理程序

RichFaces: Received 'success' event from <input id=uploadF:j_idt1136 ...>
RichFaces: Received 'complete' event from <input id=uploadF:j_idt1136 ...> 

所以,简单的问题:如何让弹出窗口关闭以及要重新渲染的组件?

1 个答案:

答案 0 :(得分:1)

我不确定问题是否与a4j:ajax直接相关,或者需要做些什么来使其与a4j:ajax一起使用,但以下代码似乎有效与f:ajax

<h:form id="formId">
    <h:commandLink value="popup"
        onclick="#{rich:component('testPop')}.show(); return false;" />
</h:form>

<rich:popupPanel id="testPop" autosized="true">
    <h:form id="uploadF" enctype="multipart/form-data">
        <h:inputFile value="#{bean.file}">
            <f:ajax listener="#{bean.storeFile()}" render="@form :fileListTbl"
                onevent="eventHandler"/>
        </h:inputFile>
    </h:form>
</rich:popupPanel>

<script>
    function eventHandler(event)
    {
        if (event.status == 'success')
        {
            #{rich:component('testPop')}.hide();
        }
    }
</script>