Saturday, June 6, 2015

Why URI Encoding...?


Most of you must heard about URI Encoding...

Why do we need to Encode URIs?

It is because otherwise servers cannot identify what we sent there.

When we are accessing/using urls we cannot add spaces there. While sending a GET request you may want to add spaces there. Then how do you send those data..?
When we are accessing/using urls we cannot add '/' there. '/' is reserved for use as a component separator. Then how do you send those data..?
Consider that you want to send a XML file attached there..

Here comes the URI encoding.

For example:
you want to encode this
http://www.mysite.com/?XML=<cs><o n="authcode" v="d82709ae"/><c n="FlightSearch"><q n="StartDate" v="18-May-2015"/><q n="EndDate" v="21-May-2015"/></c></cs>

into this
http://www.mysite.com/?XML=%3Ccs%3E%0A%3Co%20n=%22authcode%22%20v=%22d82709ae%22/%3E%0A%3Cc%20n=%22FlightSearch%22%3E%3Cq%20n=%22StartDate%22%20v=%2218-May-2015%22/%3E%0A%3Cq%20n=%22EndDate%22%20v=%2221-May-2015%22/%3E%3C/c%3E%0A%3C/cs%3E


You can try it here..


URL:






Cheers...!!

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..!!

Saturday, February 14, 2015

Find Gender and Birthday by NIC Number


National Identity Card number is unique for each Sri Lankan.
At a glance it is just a sequence of numbers; but it contains some hidden details such as the persons gender and date of birth.
You can calculate those from below form. Enter your NIC no and click on "GO" button.
Note: There are two sections for Old format NIC and New format NIC.

Old NIC No  :
Gender   :
Birthday : 

New NIC No  :
Gender   :
Birthday : 


Cheers..!!