9 Replies Latest reply: Oct 7, 2012 2:03 PM by Timo Hahn RSS

    Command button disabled after af:fileDownloadActionListener

    hofespet
      Hi,

      Jdev 11.1.1.4.0

      I trigger af:fileDownloadActionListener from a commandButton.
      Because I need to call javascript before I have implemented the approach described in this blog:
      https://blogs.oracle.com/jdevotnharvest/entry/how_to_ensure_custom_serverlistener_event_fires_before_action_events
      <af:commandButton id="cbExport" text="Export" immediate="true"
                                      binding="#{ExcelExportToolbarButton.exportButton}">
                     <af:clientListener type="action" method="getCSSContent"/>
                      <af:serverListener type="readCSSContentServerListener"
                                         method="#{ExcelExportToolbarButton.readCSSContentEventHandler}"/>
                      
                       <af:fileDownloadActionListener filename="test_export.xls"
                                                     contentType="text/html;chatset=UTF-8"
                                                     method="#{ExcelExportToolbarButton.exportCollection}"/>
      Problem:
      The af:commandButton keeps disabled after fileDownloadActionListener.
      When I scroll in an af:table which is placed on the same page then the button gets enabled again.
      I have already tried addPartialTarget and partialSubmit=true/false but without success.

      How to enable the button again?

      regards
      Peter
        • 1. Re: Command button disabled after af:fileDownloadActionListener
          Timo Hahn
          How about the other approach: use a hidden button for the file download listener and call this button from the server listener after you are done with you work?

          Timo

          Edited by: Timo Hahn on 05.10.2012 16:10
          A sample http://wp.me/pcBZk-42
          • 2. Re: Command button disabled after af:fileDownloadActionListener
            hofespet
            Hi Timo,

            I have tried your approach but without success.

            regards
            Peter
            • 3. Re: Command button disabled after af:fileDownloadActionListener
              Timo Hahn
              You mean that you could call the Java script and got to the server listener, the queuing works OK, the download starts but the button you clicked on in the first place its disabled?

              Timo
              • 5. Re: Command button disabled after af:fileDownloadActionListener
                Timo Hahn
                Hm, I changed my sample to mimic your use case (still using the solution of the sample) and it worked OK. My button behaves normal. So I think there is something in your javascript (e.g. event.cancel) which results in the behavior you see.

                Only other thing is that I run my sample using 11.1.2.3.0.

                Timo
                • 6. Re: Command button disabled after af:fileDownloadActionListener
                  hofespet
                  Hi Timo,

                  I have just created a test application with minimum on coding based on HR schema and the button still keeps disabled.

                  In my java script I have to cancel the original event to force the correct calling order (1. Javascript --> 2. Sever Listener code --> 3. method of af:fileDownloadListener)

                  Here my code of the java script
                  function consoleLog(msg) {
                      if (typeof console !== "undefined") {
                          console.log(msg);
                      }
                  }
                  
                  function testScript (event) {
                    consoleLog ("calling sequence 1");
                  
                    /* determine the element which triggered this script */
                    var element = event.getSource();
                    
                    /* create the parameter to pass the css content to backing bean */
                    var param = {testParameter:"This is the parameter value"};
                    
                    /* queue the event to pass the css content to backing bean */
                    consoleLog ("trigger serverEventHandler");
                    var custEvent = new AdfCustomEvent(element, "testServerEventHandler", param, true);
                    consoleLog ("queue the event");
                    custEvent.queue (false); /* false ==> custom event as non-partial submit (needed for af:fileDownloadActionListener) */
                    /* cancel event to avoid the call of the af:fileDownloadActionListener method.
                     * Before this method can be called the event handler for "testServerEventHandler" 
                     * must be processed. */
                    consoleLog ("cancel the old event");
                    event.cancel();
                  }
                  Here the code snippet of my backing bean.
                    public void testExport(FacesContext facesContext,
                                                    OutputStream os) throws IOException,
                                                                            NoSuchMethodException,
                                                                            IllegalAccessException,
                                                                            InvocationTargetException {
                        System.out.println("caller sequence 3");
                        OutputStreamWriter rw = new OutputStreamWriter(os, "UTF-8");
                  
                        rw.append (testParameter);
                        rw.close();
                  
                        /* Close the OutputStream */
                        os.close();
                    }
                  
                    /**
                     * 
                     * @param clientEvent event from java script
                     */
                    public void testServerEventHandler(ClientEvent clientEvent) {
                        System.out.println("caller sequence 2");
                        testParameter = clientEvent.getParameters().get("testParameter").toString();
                  
                        /* Queue an event on export button which simulates a click on the button.
                         * This is needed to trigger af:fileDownloadActionListener.
                         * (The original event has been canceled in the java script) */
                     
                        ActionEvent event = new ActionEvent(exportButton);
                        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
                        event.queue();
                    }
                  
                    public void setExportButton(RichCommandButton exportButton) {
                        this.exportButton = exportButton;
                    }
                  
                    public RichCommandButton getExportButton() {
                        return exportButton;
                    }
                  Do you have the same calling sequence in your test application than me? (1. Javascript --> 2. Sever Listener code --> 3. method of af:fileDownloadListener)
                  If yes, can you post your code here?

                  BTW: Also tested with 11.1.2.1 but same behaviour than with 11.1.1.4.0

                  regards
                  Peter
                  • 7. Re: Command button disabled after af:fileDownloadActionListener
                    Timo Hahn
                    Peter,
                    I use the same sequence. I put my sample (with your use case) here http://tompeez.files.wordpress.com/2012/10/blogfiledownloadtest-zip.doc
                    You can download it and analyze it in more detail. I see some differences, which I can't comment on as I don't see the page source. The sample is build using 11.1.2.1 and tested in 11.1.2.3

                    Timo
                    • 8. Re: Command button disabled after af:fileDownloadActionListener
                      hofespet
                      Hi Timo,

                      Thanks for your example.
                      In your code the event to trigger the actual file download from the hidden button is fired from java script.
                      In my code I do this in the backing bean.

                      I'll do further tests tomorrow.

                      In your code the method checkBeforeDLButton is unused.
                      In this method the event is triggered from java too.
                      Does your code works with this method too?

                      regards
                      Peter
                      • 9. Re: Command button disabled after af:fileDownloadActionListener
                        Timo Hahn
                        Peter, that the button is queued from javascript is the whole point. There is a problem if you don't do it this way (check this http://jobinesh.blogspot.de/2010/01/customizing-execution-of-to-validate.html). The solution is to queue the action from javascript.
                        The method checkBeforeDLButton is not used anymore for this reason.

                        Timo