2014-01-27 40 views
2

我在Wildfly-8.0.0.CR1上使用Richfaces-4.3.5,從<rich:fileUpload>遷移,這對於JSF-2.2/Servlet-3.0不起作用。我在這個片段中替換它:如何才能對<h:inputFile>完成的上傳做出反應?

<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

我不確定問題是否與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> 
相關問題