Sunday, March 29, 2015

Automatic data refresh Oracle ADF tables using ADF Poll

As you know we are using Oracle ADF tables to represent data at database tables, views, etc... When application loads tables load data from db and displays those. But if data is changed or new added or existing data get deleted..?? Then we need a mechanism to display the updated data.

We can use ADF Poll for this. Then we can use poll event to refresh table data after every time period.


Steps:



  1. Insert Poll inside “panelHeader” in which table is located
  2. Set poll interval from poll properties- This is the time gap for every refresh. for Ex: if you have set poll interval as 5 seconds table data will be refreshed after every 5 seconds.

    If you want you can take this value from template properties.
    Value you entered: #{manage_Template.dataRefreshRate}
    (This is used to get the refresh value by using the method in manage_Template)
  3. Set partial triggers from poll properties - Here you can specify the table which you want to get refreshed. for Ex: table1
  4. Set partial triggers from ADF table - Give the poll id for this field.
    Table --> Behavior --> Partial Triggers --> Set poll id here
  5. Set Poll Listener from poll properties - This is the most important mapping which links what is the action has to be taken out when poll event triggers

    Type a method e.g.: refreshSPIntentionTab ()
    Press enter
    (Method is created in .java file)
  6. Add the below code to the poll listener method using appropriate VOIterators


    There are three stages at this code.


    STAGE 1:

    If you want only to refresh the table you can use the current method. At this method you can’t maintain the current row position after table refresh.

    public void refreshSPIntentionTab (PollEvent pollEvent) {
            FacesContext fctx = FacesContext.getCurrentInstance();
            ValueBinding dcb = fctx.getApplication().createValueBinding("#{bindings}");
            DCBindingContainer bindings1 = (DCBindingContainer) dcb.getValue(fctx);
            if(bindings1!=null){
                DCIteratorBinding dciter = bindings1.findIteratorBinding("DeliveryIntentionsSPApprovVO1Iterator ");
                if(dciter!=null){
                    if(dciter.getCurrentRow()!=null){  
                        dciter.executeQuery();
                    }
                }
            }
        }


    STAGE 2:

    If you want to refresh the table and maintain the current row position after the table refresh.... We can apply this only for a single table; not for master-detail tables.

    public void refreshSPIntentionTab (PollEvent pollEvent) {
            FacesContext fctx = FacesContext.getCurrentInstance();
            ValueBinding dcb = fctx.getApplication().createValueBinding("#{bindings}");
            DCBindingContainer bindings1 = (DCBindingContainer)dcb.getValue(fctx);
            if (bindings1 != null) {
                DCIteratorBinding dciter = bindings1.findIteratorBinding("DeliveryIntentionsSPApprovVO1Iterator ");
                if (dciter != null) {
                    if (dciter.getCurrentRow() != null) {
                        Key current_row_key = dciter.getCurrentRow().getKey();
                        dciter.executeQuery();
                        if (current_row_key != null) {
                            try {
                                dciter.setCurrentRowWithKey(current_row_key.toStringFormat(true));
                            } catch (Exception ex) {
                                System.out.println("Exception in current_row_key");
                            }
                        }
                    }
                }
            }
        }


    STAGE 3:

    If you want to maintain the current row position of master-detail tables after the table refresh, use the following methods.

    // for the master table refresh
    public void refreshSPIntentionTab (PollEvent pollEvent) {
            FacesContext fctx = FacesContext.getCurrentInstance();
            ValueBinding dcb = fctx.getApplication().createValueBinding("#{bindings}");
            DCBindingContainer bindings1 = (DCBindingContainer)dcb.getValue(fctx);
            DCIteratorBinding it = bindings1.findIteratorBinding("DeliveryIntentionsSPApprovVO1Iterator");
            ViewObject vo = it.getViewObject();
            Row row = vo.getCurrentRow();
            Key key = row.getKey();
            int rangePosition = vo.getRangeIndexOf(row);
            int rangeStart = vo.getRangeStart();
            if(rangePosition==(-1)){
                rangePosition=rangePositionCommon;
                rangeStart=rangeStartCommon;
                }
            vo.executeQuery();
            vo.setRangeStart(rangeStart);
            Row[] rows = vo.findByKey(key, 1);
            if (rows != null && rows.length == 1) {            
                vo.scrollRangeTo(rows[0], rangePosition);
                vo.setCurrentRowAtRangeIndex(vo.getRangeIndexOf(rows[0]));
                rangePositionCommon=rangePosition;
                rangeStartCommon=rangeStart;
            }
        }

    // for the detail table refresh
    public void refreshSPIntentionTab (PollEvent pollEvent) {
            FacesContext fctx = FacesContext.getCurrentInstance();
            ValueBinding dcb = fctx.getApplication().createValueBinding("#{bindings}");
            DCBindingContainer bindings1 = (DCBindingContainer) dcb.getValue(fctx);
            if(bindings1!=null){
                DCIteratorBinding dciter = bindings1.findIteratorBinding("DeliveryIntentionsSPApprovVO1Iterator ");
                if(dciter!=null){
                    if(dciter.getCurrentRow()!=null){  
                        dciter.executeQuery();
                    }
                }
            }
        }

Now all the setup processes are completed. Please check your new functionality.


Cheers..!!

8 comments:

  1. There are lots of information about oracle have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get to the next level in oracle. Thanks for sharing this.

    Oracle Training in Chennai | Oracle Course in Chennai | hadoop training in chennai

    ReplyDelete
  2. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,
    cognos Training in Chennai

    ReplyDelete
  3. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Hadoop Training Institute In chennai

    amazon-web-services-training-institute-in-chennai

    ReplyDelete
  4. let others light their candles with this.. I'm glad :)

    ReplyDelete
  5. Thanks for such a wonderful help...Keep posting...This Blogs are a part of others Enhancement in Their careers...Well Done works
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete