4 Replies Latest reply: Sep 4, 2013 10:12 AM by Lars Hansen RSS

    Set VO bind variable on page loading programmatically

    Lars Hansen

      Greetings everyone!

      I use JDeveloper version 11.1.2.3.0

       

      I am currently trying to get some filtered data from a VO, based on a WHERE clause with a bind variable. This process should be done on page load. I have to set this bind variable with the id of the logged user (the part of getting this id is already achieved and used somewhere else). My current approach is defining a managed bean with pageFlow scope. Inside this i have a method in which i retrieve the id and i set it as the parameter value. The code snippet:

            BindingContainer bindings = getBindings();
              OperationBinding operationBinding = bindings.getOperationBinding("getUserIdFromUsername"); //getUserIdFromUsername is a method defined in the AppModule and exposed in the client interface
             operationBinding.getParamsMap().put("username", getUserName());
            Object userID = operationBinding.execute();
              setUserId(Integer.parseInt(userID.toString()));
             System.out.println("THE USER ID IS: "+getUserId());
             BindingContainer bindings2 = getBindings();
             OperationBinding operationBinding2 = bindings.getOperationBinding("ExecuteWithParams");  // i've dragged and dropped the ExecuteWithParams operation into the page
             operationBinding2.getParamsMap().put("userId", getUserId());  // userId is the bind variable which i'm talking about
              Object result = operationBinding2.execute();
      
      
      

      Then, i call this method on BeforePhase in the page view. It works, i get the filtered data and the println shows me the correct ID. The problem is that each time i select a row in the table showing the data, the page seems to reload and it always get the selection back at the very first row.

      What am i doing wrong? May be this is not the right approach, as i've seen some other posts about this topic but they are not very clear to me.

       

      Please advice

        • 1. Re: Set VO bind variable on page loading programmatically
          Cvele_new_account

          1. call this method in the executable section of the pagedef, only if not postback , for example:

           

          <invokeAction id="call_method" Binds="method" Refresh="prepareModel"
                        RefreshCondition="#{!requestContext.postback and empty bindings.exceptionList}"/>

           

                --  OR --

          2. if you use task flow, call him as  method call activity before going to the page.

           

          Message was edited by: Cvele_new_account

          • 2. Re: Set VO bind variable on page loading programmatically
            Lars Hansen

            I've already tried the second approach before.I've just tried your first suggestion and in both cases i don't get any data. Am i missing something?

            • 3. Re: Set VO bind variable on page loading programmatically
              Sai Yeluri

              Approach1:

              --------------

              Drag and Drop an Application  method as Default Method Call Activity, then draw a control flow case from the method to your page.

              In the application module method, implement appropriate logic.

               

              Approach2:

              --------------

              Using a combination of client listener and server listener will also help.

              <af:clientListener method="onLoadAction" type="load"/>

              <af:serverListener type="MyCustomServerEvent"

              method="#{backingBeanScope.editBean.onLoadListener}"/>

               

               

              function onLoadAction(event){

                         /*alert(':::: onSave ::');*/

                         AdfCustomEvent.queue(actionEvent.getSource(),

                                       "MyCustomServerEvent",

                                       {},

                                       true);

                     actionEvent.cancel() ;

                     actionEvent.stopPropagation();

                     }

              • 4. Re: Set VO bind variable on page loading programmatically
                Lars Hansen

                OK, this is what i've done. I've created the method responsible for setting the bind variable value of the VO query in the AppModule instead of inside the bean (this method also executes the query) and exposed it to the client interface. After that i've created the method call in the bindings section of the pagedef (where it gets the id value from the bean in the original post), and followed Cvele_new_account suggestion invoking the method as follows:

                <invokeAction id="call_method" Binds="method" Refresh="prepareModel"         

                   RefreshCondition="#{!requestContext.postback and empty bindings.exceptionList}"/>

                Thank you for the help guys!