Saturday 19 March 2016

Issues closing popup in filedownload actionlistener : ADF 12.2.1

Requirement: I have a pop up with two input text fields and Ok and Cancel button. on click of OK button, i have to pass user entered value in input text and suppose to call af:fileDownloadActionListener to download ODS file

Problem Faced: I was not able to close the pop up after file download

Reason : FileDownloadListener will invoke facesContext.responseComplete() so this will suppress additional processing. (you can't have two http responses for one http request)

Solution/Approach : Programmatically invoking button which has af:fileDownloadActionListener associated with it in a bean method

Here is what i have done

I have used two buttons one which is hidden and one to show on af:pop up. Here hidden button has af:fileDownloadActionListener  associated with it. from the visible button action i am programmatically invoked hidden button.

my jsff code


<af:button text="OK"
                                                                   id="b2"
                                                                   binding="#{backingBeanScope.TestBean.bindDownloadButton}"
                                                                   visible="false" clientComponent="true" partialSubmit="false">
                                                            <af:fileDownloadActionListener contentType="application/vnd.oasis.opendocument.spreadsheet"
                                                                                           filename="#{backingBeanScope.MaintainCostChangeInductionBackingBean.fileName}"
                                                                                           method="#{backingBeanScope.TestBean.downloadODSFile}"/>

       </af:button>
                                                        <af:button text="OK"
                                                                   id="b8"
                                                               
                                                                   actionListener="#{backingBeanScope.TestBean.downloadFromSTGData}"/>


Backing Bean code Logic



// Programatically invoking button action

public void downloadFromSTGData(ActionEvent actionEvent) {

                    FacesContext fctx = FacesContext.getCurrentInstance();
                    String buttonId = bindDownloadButton.getClientId(fctx);
                    StringBuilder script = new StringBuilder();
                    script.append("var dlButton = AdfPage.PAGE.findComponentByAbsoluteId('" + buttonId + "');");
                    script.append("dlEvent = new AdfActionEvent(dlButton);");
                    //script.append("dlButton.queueEvent(dlEvent, true);");
                    script.append("dlEvent.forceFullSubmit();");
                            script.append("dlEvent.noResponseExpected();");
                            script.append("AdfActionEvent.queue(dlButton, dlButton.getPartialSubmit());");
                    ExtendedRenderKitService erks =
                        Service.getService(fctx.getRenderKit(), ExtendedRenderKitService.class);
                    erks.addScript(fctx, script.toString());
                   // Get Pop up binding and call hide()
                    upldDwnldPopup.hide();

}


Hope this helps!!!!

No comments:

Post a Comment