Please disable your adblock and script blockers to view this page

Search this blog

Saturday 1 August 2015

ADF Baiscs: Define and remove named bind variable in viewObject at runtime programmatically

This post is about creating named bind variable in viewObject at run time and filter viewObject using this bind variable in WHERE Clause of ViewObject programmatically .

Defining WHERE Clause and Bind Variable name and default value -

        //Get ViewObject
        ViewObject vo = iter.getDepartments();

        //Apply desired WHERE Clause and declare bind variable name
        vo.setWhereClause("DEPARTMENT_NAME=:BindDepartmentName");

        //Define this variable as ViewObject Bind Variable , You can also set default value for this
        vo.defineNamedWhereClauseParam("BindDepartmentName", "Purchase", null);

        // Execute ViewObject to finally apply where clause
        vo.executeQuery();




Setting value of Bind Variable-


        //Setting Value of Bind Variable
        vo.setNamedWhereClauseParam("BindDepartmentName", "Finance");
        vo.executeQuery();


Getting value of Bind Variable-


        //Get value of Bind Variable
        vo.getNamedWhereClauseParam("BindDepartmentName");


Removing WHERE Clause and Bind Variable after use-


        //Remove where clause
        vo.setWhereClause(null);
        //Remove Bind Variable
        vo.removeNamedWhereClauseParam("BindDepartmentName");
        vo.executeQuery();

Cheers :) Happy Learning

8 comments :

  1. Hi Ashish, but actually wanted to if we have to use comma separated values, in the sense if we have to use IN clause then how we should go through. The one which you have posted here is w.r.t to single value bind variable.

    ReplyDelete
    Replies
    1. Pruthiviraj

      You can google that, there are lots of blog post about using IN clause in viewObject
      Check- Passing comma separated values as Bind variable for View Object Query IN operator

      Ashish

      Delete
  2. Actually I have already tried the post which you have advised but there it's including subString as well. Suppose I have to see the results of Dept=164 then it's showing the result of Dept=164 and 64 as well. And one more problem I'm facing, I have got a PanelTab where two tabs are there. In both the tabs tables are displayed. Both the tables refers to same DB table, but only one difference is that views of both the tables are difference based on one column Status. In first tab results are displayed based on status='Y' and in next tab results are displayed based on status='N'. I can move the records from 2nd tab to first and vice-versa. But whenever I'm moving data from 2nd tab to 1st tab so ideally it should display in 1st tab. But when I'm trying to move to 1st tab to see the moved record the whole table becomes empty. Th ViewObject which has been used to show the results is giving 0 rowcount.

    ReplyDelete
    Replies
    1. When I'm moving the data from 2nd tab to first then I'm changing the status of that selected record to status='Y' so that it will be displayed on 1st tab.

      Delete
    2. and how are you moving data , by changing status ?
      if yes then either you have to commit data and exeute viewObject or set your viewCriteria mode to both (DB & Memory)

      Delete
    3. Yes I'm moving the data by updating the status. I'm committing the data and then trying to execute the View Object. The ViewObject consists of Bind Variables and from View Layer Backing bean I'm execution vo.setNamedWhereClauseParam("bind_variable", data) vo.executeQuery() and vo.getRowCount() gives 0 rows.

      Delete
    4. I haven't used viewCriteria rather I've used Bind Variables to access DB functions.

      Delete
    5. Pruthvi

      It's weird. Are you using any other mehtod like exeucteEmptyRowSet ?
      You should post this question in Jdeveloper & ADF Forum

      Ashish

      Delete