Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label ViewObjectImpl. Show all posts
Showing posts with label ViewObjectImpl. Show all posts

Monday 13 November 2017

ADF Basics: Add the row at the end of ViewObject's current RowSet in ADF


This post is about adding a row at the end of current rowset of viewObject without using table or any other UI components binding


Here I have a Department ViewObject (HR Schema), dropped as a table on page and a button to add new row, this button calls a method from model using binding layer 

Thursday 4 May 2017

Implement contains/endswith behavior in model based autoSuggest Lov (Input list and combo box)


Hello All

Hope Everyone knows about list of values and autoSuggest beahvior of ADF Framework,
For those who are new to framework can look at this post
ADF Basics : Implementing auto suggest behavior in ADF Faces lov (list of values)

Friday 16 January 2015

Setting view object bind variable (Override bindParametersForCollection, prepareRowSetForQuery, executeQueryForCollection )

Hello All,
This post is about a very basic question- How to set bind variable of a view object ?
and there are multiple posts about it that describes multiple ways to do this
Using setNamedWhereClause
Using VariableValueManager 
Using setter method in VOImpl class

But Sometimes we can not assign bind variable value in declarative way for first time execution as value source for bind variable is fixed but it's value may change at runtime from n number of events



So for this type of requirement we can set bind variable's value in such a way so that we need not to write code everywhere to set changed value.
See how can we do this -

  • Create a Fusion Web Application and prepare model using Departments table of HR Schema




  • Open Departments viewObject add a bind variable in it's query , this bind variable is further used to set value and filter result set





  • Create Java class for Department view object, goto java tab of Departments VO and click on edit icon of Java Classes and select "Generate ViewObject Class"





  • Now we can set bind variable's value by overriding 3 methods of DepartmentVOImpl class

1. Overriding bindParametersForCollection in ViewObject java class -

This method is used to set bind variable's value by framework, framework supplies an array of all bind variable to this method We can override this method to set value of bind variable ,
Open DepartmentVOImpl class and click on override methods icon on top of editor
It will open a window that consist all methods , search by name and click on ok



See the code in DepartmentVOImpl-


    /**@override Method to set bind variable's value at runtime (Framework Internal Method)
     * @param queryCollection
     * @param object
     * @param preparedStatement
     * @throws SQLException
     */
    protected void bindParametersForCollection(QueryCollection queryCollection, Object[] object,
                                               PreparedStatement preparedStatement) throws SQLException {
        for (Object bindVar : object) {
            // Iterate over bind variable set and find specific bind variable
            if (((Object[])bindVar)[0].toString().equals("BindDeptId")) {
                // set the bind variable's  value
                ((Object[])bindVar)[1] = 100;

            }
        }
        super.bindParametersForCollection(queryCollection, object, preparedStatement);

    }

2. Overriding prepareRowSetForQuery in ViewObject java class -

This method (introduce in 11.1.1.5 release) executes before bindParametersForCollection , same thing can also be done in this method 
Override method in Impl class 


See the Code in DepartmentsVOImpl-


    /**@override Method to prepare RowSet for execution(Framework Internal Method)
     * @param viewRowSetImpl
     */
     public void prepareRowSetForQuery(ViewRowSetImpl viewRowSetImpl) {
        //Set Bind Variable's value 
        viewRowSetImpl.ensureVariableManager().setVariableValue("BindDeptId", 100);
        super.prepareRowSetForQuery(viewRowSetImpl);
    } 

3. Overriding executeQueryForCollection in ViewObject java class -


This method invokes just before framework executes rowset , avoid setting bind varibale in this method because it is not called before some methods as getEstimatedRowCount(), So whenever you try to get rowcount it will return wrong values 
still it works and sets the bind varible value and executes rowset, again override method



See the Code in DepartmentsVOImpl-


    /**Method to excute viewObject rowSet(Framework Internal Method)
     * @param object
     * @param object2
     * @param i
     */
    protected void executeQueryForCollection(Object object, Object[] object2, int i) {
        for (Object bindVar : object2) {
            // Iterate over bind variable set and find specific bind variable
            if (((Object[])bindVar)[0].toString().equals("BindDeptId")) {
                // Set the bind variable value
                ((Object[])bindVar)[1] = 100;

            }
        }
        super.executeQueryForCollection(object, object2, i);
    }

Now use anyone of these methods to set bind variable value and run application module, check result
It is showing data for DepartmentId 100.

Thanks, Happy Learning :)

Tuesday 10 June 2014

Export ViewObject dataset to XML, Generate customized XML file using ViewObject in Oracle ADF

Hello All,
this post is about exporting a viewObject data to a XML document.
Sometimes we need to generate XML document with the same data in ViewObject, for this ADF provides a facility to directly export data to a XML document using ViewObjectImpl class

See the steps to generate XML for a ViewObject

  • Create a Fusion Web application and model using HR schema (Departments & Employees) table (master detail relation using viewLink)


  • Now to generate XML, i have used writeXML method of ViewObjectImpl class, it produce XML using two parameters



  • from oracle docs-
    writeXML(int depthCount, long options)
    here depthCount - no. of ViewLink levels that should be traversed to produce XML
    options- how many rows you want to export, It can be set any of flags given below
    XMLInterface.XML_OPT_ALL_ROWS
    Includes all rows in the view object's row set in the XML.

    XMLInterface.XML_OPT_LIMIT_RANGE
    Includes only the rows in the current range in the XML.

  • created a method in DepartmentsVOImpl class to export data to XML, added it to client Interface

  •     /**Method to generate XML from ViewObject data
         * @param level
         * @return
         */
        public String writeVoToXml(int level) {
            FileOutputStream out;
            ByteArrayOutputStream opStream = new ByteArrayOutputStream();
            try {
                // Generating XML for All rows and adding it to Output Stream
                ((XMLNode) this.writeXML(level, XMLInterface.XML_OPT_ALL_ROWS)).print(opStream);
                System.out.println(opStream);
                // Creating a XML document in D Drive
                out = new FileOutputStream("D://Departments.xml");
                out.close();
    
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
    
            return opStream.toString();
    
        }
    


  • Now run application module to execute method and see generated XML on console

  • BC4J Tester

    ViewObject XML

  • i have created a simple page with a af:codeEditor to show generated XML , button to generate XML and a spinner to pass depth level of viewLink accessor

  • In case depth level is '0' , it export data only for Departments viewObject

    Change level to '1' , Now it generate XML for Departments --> Employess relation


  • now to how to customize XML ? How to change default tags for attribute names and rows ?
  • To change attribute label (tag in xml)- Suppose i have to change DepartmentName to Name in XML
  • Add attribute level custom property named XML_ELEMENT to a value AnyOtherName to change the XML element name used for that attribute


  • To change Row label (tag in xml)- Suppose i have to change DepartmentsVORow to DepartmentLine in XML
  • Add ViewObject level custom property named XML_ROW_ELEMENT to a value AnyOtherName to change the XML element name used for that Row


  • Now Run and see generated XML -
Cheers :-) Happy Learning