2017-01-11 104 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。