2017-01-11 66 views
0

我試圖用JavaScript執行一個按鈕的點擊操作,我想執行一個應該在後臺bean中運行的方法。ADF Jdeveloper - 在JSP上使用javascript執行點擊按鈕

這是我的資源

 <af:resource type="javascript"> 
      function closePopup(event) { 
       //var dialog = event.getSource(); 
       //var popup = dialog.findComponent("pt1:b17"); 
       //console.log(popup); 
       //popup.click(); 
       //$("#pt1:b17").trigger("click"); 
       //popup.hide(); 
       //event.cancel(); document.getElementById('pt1:b17') 
       console.log("trigger the event"); 

       eventFire(document.getElementById(AdfPage.PAGE.findComponentByAbsoluteId('pt1:b17').getClientId()), 'click'); 
      } 

      function eventFire(el, etype) { 

       if (el.fireEvent) { 
        console.log("true"); 
        el.fireEvent('on' + etype); 
       } 
       else { 
        console.log("false"); 
        var evObj = document.createEvent('Events'); 
        evObj.initEvent(etype, true, false); 
        el.dispatchEvent(evObj); 
       } 
      } 
     </af:resource> 

現在,這是我的JSP代碼:

                <af:group id="g4"> 
                    <af:commandButton text="Aceptar" id="b17"> 
                     <af:fileDownloadActionListener contentType="excelHTML" filename="#{viewScope.mbFiles.file_name}" method="#{viewScope.mbFiles.generateFile}"/> 
                    </af:commandButton> 
                    <af:button text="test" id="buttonTest"> 
                     <af:clientListener method="closePoPup" type="action"/> 
                    </af:button> 
                   </af:group> 

我不能觸發我的下載文件的方法。

在此先感謝。

回答

0

我張貼在另一個問題的答案:

https://stackoverflow.com/a/41708683/5120410

的代碼是這樣的:

Java中的方法:

public void prepareForDownloadAction(ActionEvent act) { 

FacesContext context = FacesContext.getCurrentInstance(); 
ExtendedRenderKitService erks = 
Service.getService(context.getRenderKit(), 
     ExtendedRenderKitService.class); 

erks.addScript(context, "customHandler();"); 
} 

現在,這是我的Javascript方法:

<af:resource type="javascript">    

     function customHandler(evt) { 
      console.log(evt); 

      var exportCmd = AdfPage.PAGE.findComponentByAbsoluteId("pt1:b17"); 
      console.log(exportCmd); 
      var actionEvent = new AdfActionEvent(exportCmd); 
      console.log(actionEvent); 
      actionEvent.forceFullSubmit(); 
      actionEvent.noResponseExpected(); 
      actionEvent.queue(false); 

      setTimeout(function(){hidePopup();}, 1000);  


     }          

     function hidePopup() { 

      var popup = AdfPage.PAGE.findComponent("pt1:popupAceptarDescargarPlantilla::content"); 

      popup.hide(); 

     } 

    </af:resource> 

Greatings。