Programmatically sorting the data of View Object in Oracle ADF


To Programmatically sort the data of View Object in Oracle ADF, use the following steps:


  • Open the Java Section of your View Object and Generate the View Object class by checking the below check boxes.


  • Above steps will create a Java File for your view object (Employees_VOImpl in our case)
  • Checking the option "Include bind variable accessors" will create getter & setter methods for each attribute of your view object
  • Now go to this java file and write the below code in the constructor of the class

package model.BussinessComponents.ViewObjects;

import oracle.jbo.SortCriteriaImpl;
import oracle.jbo.ViewObject;
import oracle.jbo.server.ViewObjectImpl;

public class Employees_VOImpl extends ViewObjectImpl {
    /**
     * This is the default constructor (do not remove).
     */
    public Employees_VOImpl() {
    
        this.setProperty(ViewObject.PROP_ALWAYS_USE_SORT, "true");
        SortCriteriaImpl[] sortCriteria =new SortCriteriaImpl[] 
                                        { new SortCriteriaImpl("FirstName",false) };
                 this.setSortCriteria(sortCriteria);

    }
}
  • Here we have used the below constructor of the SortCriteriaImpl class:

      public SortCriteriaImpl(java.lang.String attribute_name, boolean is_sort_desc)


So, new SortCriteriaImpl("FirstName",false) means that we are sorting the view object with Attribute "FirstName" and in Ascending order (since, is_sort_desc is false). Attribute name is case sensitive, so be careful.



That's it!
Now your view object will be sorted according to FirstName attribute in ascending order.

Comments