Tuesday, March 30, 2010

Bit #2 - Setting a bind variable value programmatically

To set the value of a bind variable programmatically, you will need to first get the View Object where the bind variable is defined. Then from the View Object you need to get access to the VariableValueManager via the call ensureVariableManager(). Finally you need to call setVariableValue() on the VariableValueManager to set the bind variable to a specific value. Once all these are done, execute the View Object query with the new bind variable value by calling executeQuery()  on the view as shown below.

Example:

        ViewObjectImpl view = this.getSomeView();
        VariableValueManager vm = view.ensureVariableManager();
        vm.setVariableValue("bindVariableName", value);
        view.executeQuery();

Context:

Application Module Implementation class
View Object Implementation class


6 comments:

  1. Hi,
    I use an other way :
    ViewObjectImpl view = this.getSomeView();
    view.setNamedWhereClauseParam("bindVariableName", value);
    view.executeQuery();
    Is there a better way than an other?
    Clément

    ReplyDelete
    Replies
    1. Hi Clement,
      Your way is good becuase in main post i am unable to set bind variable value.

      Maroof

      Delete
  2. Hi Clément

    The difference is that setNamedWhereClauseParam() will set the bind variable value for the default row set only. To make sure that the bind variable value is set for all row sets, use the View Object's VariableValueManager and call setVariableValue() on it instead. I suggest using the later to avoid calling setNamedWhereClauseParam() each time.

    ReplyDelete
  3. Congratulations Nick; It's an excellent article.

    ReplyDelete
  4. what is this getSomeView() function??

    ReplyDelete
    Replies
    1. For each View Object (VO) that you add to the Application Module Data Model, you have a VO getter method. This is just an example that returns a VO object called "SomeView" for the sake of demonstrating this code bit.

      Delete

Related Posts Plugin for WordPress, Blogger...