Pageviews

Monday, November 24, 2014

Tips on ADF page refresh, UI Component refresh and file download



Tip 1: Method to programmatically refresh ADF page      

This is not always recommended, but in case you need to refresh the entire view then use the below managed bean method to refresh the page programmatically.
 


Managed bean layer:

    public void refresh() {
           FacesContext facesContext = FacesContext.getCurrentInstance();
           String refreshpage = facesContext.getViewRoot().getViewId();
           ViewHandler  viewHandler =facesContext.getApplication().getViewHandler();
           UIViewRoot viewroot =  viewHandler.createView( facesContext, refreshpage);
           viewroot.setViewId(refreshpage);
           facesContext.setViewRoot(viewroot);
     }





Tip 2: Force a refresh on a UI component.

Example 1:
This examples dynamically sets the disable flag property to true/false during run time.

View layer:

                <af:button text="Download" partialSubmit="true" id="b2"
                           disabled="true" binding="#{viewScope.datasource.downloadButton}">

Managed Bean layer:


    private RichButton downloadButton;

 AdfFacesContext.getCurrentInstance().addPartialTarget(downloadButton);




Example 2:

This example refresh the table component when ever the data is refreshed with new set of values.

Managed Bean Layer:

 private RichTable issueTable;

AdfFacesContext.getCurrentInstance().addPartialTarget(issueTable);


Tip 3:  ADF file download

View Layer:

              <af:fileDownloadActionListener 
                                        contentType="text/csv; charset=utf-8"
                                             filename="#{viewScope.datasource.fileName}"
                                             method="#{viewScope.datasource.downloadAction}"/>


Managed bean Layer:
    private String fileName;

    public void downloadAction(FacesContext facesContext, OutputStream outputStream) throws IOException, Exception {
//  Write java code to read and download the file.

}