Set VO bind variable on page loading programmatically

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

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();

Similar Messages

  • How to set the bind variable on page load and execute query ?

    Hi All,
    I am using Jdeveloper 11.1.1.5
    I have a table called "Employee"
    Columns :- id , name , location
    Data :- 1, ,james , chicago
    2 ,Raj ,capetown
    Now i have another webservice(created as a webservice dataControl) which sends me the "id" on each time my page loads.Now the id which has been returned by webservice should be incorporated in my VO Query as in where clause to fetch the data for the respective "id" in that "Employee" table and should be rendered on form.
    Eg :- Id "2" has been sent by the webservice then the record should be fetched from database should be "2","raj","capetown".
    I know that there would be necessity of bind variable , but how do i set the bind variable on page load ?
    How can i use the bind variable appropriately ??
    Please suggest !!!!
    Thanks.

    Hi,
    Check
    http://www.orastudy.com/oradoc/selfstu/fusion/web.1111/b31974/web_services.htm#CJADCDBG
    http://thepeninsulasedge.com/frank_nimphius/2011/02/18/adf-code-corner-sample-73-released-hands-on-creating-a-search-form-using-a-pojo-ws-and-the-web-service-data-control/
    -Suresh

  • Best Practice for setting bind variable when application loads

    I am using JDeveloper 11.1.2.3.
    When my application loads, the first unbounded page has a table populated by a named query.
    I would like to set the parameter used by the named query when the page loads, to populate the initial data that is displayed.
    What is the best practice for a solution to this issue?

    user6003393 wrote:
    I am using JDeveloper 11.1.2.3.
    When my application loads, the first unbounded page has a table populated by a named query.
    I would like to set the parameter used by the named query when the page loads, to populate the initial data that is displayed.
    What is the best practice for a solution to this issue?Hi,
    You can set the bind variable on VO by overriding prepareSession() method in Application Module check this http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bcservices.htm#sthref357
    Setting bind variable on runtime http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bcquerying.htm#CHDECJHD
    Zeeshan

  • How to set a bind variable across the pages in a report

    I want to create a portal report where data will come from a table for a date range for a week.
    For e.g select event_date,last_name, event_name
    from RESOURCES
    where event_date between trunc(to_date(:curr_date,'DD-MON-RRRR'))
    and trunc(to_date(:curr_date,'DD-MON-RRRR')+ 7)
    The :curr_date is defined as a bind variable whose default value is sysdate.
    Now, when we run the report for the first time, it takes the :curr_date as
    sysdate and prints the report.
    I have two buttons in the report output like "previous week" and "next week".
    If someone presses previous week, the same report should run with curr_date
    as sysdate-7 and if someone presses next week, the report should run with
    curr_date as sysdate +7 and also the :curr_date sets to sysdate - 7 or sysdate + 7
    depending on the button pressed.
    Problem:
    How do I set the value of curr_date if someone presses any of
    previous week/next week.
    null

    Best to state your JDev version, and technology stack (eg. ADF BC) when posting.
    I can think of 2 approaches.
    1) Create a parent VO based on SELECT :bindVar FROM dual, then create links between your other VOs and the parent
    2) Create a AM client interface method that programatically sets the bind variable in each VO.
    Can you specify your use case? This one tends to come up when discussing effective from/to dated queries.
    CM.

  • JDev 11.1.2.1 Execute method (with bind variable) before page is displayed

    Hi All,
    I have a view object with a query that uses a bind variable. I drag the data control onto my .jsf page to create a table. I create a query method on a view scope bean. The query method uses the contents of one of the bean's attributes to set the bind variable for the query:
    vo.setNamedWhereClauseParam("CraIdBindVar", sessionBean.getCraId());
    I place a button on the page that invokes the query method and it populates the table. This is fine but I don't want the user to have to click on the 'query' button when they navigate to this page. I have found forums that discuss creating an AMImpl.jave method, creating a binding on the page, creating an executable for the binding. This works in that the method is executed before the page is displayed. However, the AMImpl method cannot call sessionBean.getCraid() to get the necessary data item to populate the bind variable.
    Is there a way to execute my view scope bean method before the page is displayed? Or perhaps a way for the AMImpl.java method to access the view scope variable?
    Thanks, Steve

    Steve,
    you can drag a method call activity onto the task flow. Then select the new method call activity and open the property inspector. Here you select the method from your bean in the method property. Now you first navigate to this method call activity and then to the page.
    Timo

  • Setting VO bind variable using session variable

    Hi,
    I need to get/set VO bind variable using ApplicationModuleImple or ViewObjectImple class. Does Any one know how to do it?
    I have one VO based on query like "select name from users where password = :password ". I had a bind variable to it too. now i want to set it from a session scoped variable. can i do it using ADFContext.getCurrent().getSession().get('username'); ? but somehow I am not able to get the knowledge i.e where to set bind variable. please help.

    Timo thanks for the reply, actually I don't want to do it using data control i.e drag and drop method to a page. Instead i just want to set bind variable to a session varable already got from login page.
    I got the following sollotion but don't know where to put them,
    1.
    FacesContext context = FacesContext.getCurrentInstance();
    ValueBinding vb = context.getApplication().createValueBinding("#{data}");
    BindingContext bci = (BindingContext)vb.getValue(context);
    DCDataControl dc = bci.findDataControl("AppModuleDataControl");
    ApplicationModule am = (ApplicationModule)dc.getDataProvider();
    AppModuleImpl service = (AppModuleImpl)am;
    ViewObject vo = service.findViewObject("YourViewObject").setNamedWhereClauseParam("nameBindVariable", objectValue);
    vo.executeQuery();
    what is the #{data} in second line ? if you know please let me know.
    Second Solution :
    2- In backing bean code:
    FacesContext context = FacesContext.getCurrentInstance();
    Application fapp = context.getApplication();
    JUFormBinding adfbc = (JUFormBinding)fapp.createValueBinding("#{bindings}").getValue(context);
    DCIteratorBinding iter = adfbc.findIteratorBinding("YourIterator");
    iter.getViewObject().setNamedWhereClauseParam("nameBindVariable", objectValue);
    iter.executeQuery();
    where would I get "YourIterator" ... ? I am still a new at jdev ... ;)

  • Setting a bind variable in a Shared Component Report Query

    I have defined a Shared Component Report Query in APEX using a bind variable similar to below
    Select name, id , ....
    from asset
    where id = :id
    I have also created a Report Region that displays a table where one of the columns contains a value I would like to be a link column that can launch the Report Query and pass its value to the bind parameter :id in the report query. This in turn would generate a pdf report for the details associated with that column. I am having problems setting the :id bind parameter. How do I do this?
    Can anyone help?
    Thanks

    The bind values are set from session state. So if try something like this:
    Select name, id , ....
    from asset
    where id = :P1_ID
    With P1_ID being a page item, for which you set the session state / value before generating the PDF file. So assuming you already have a page with a report and a page item, and that page item is already used in your report, then you could just create a button to download the PDF, make sure the button is a submit button, and create a branch pointing to the report query URL (or in 3.1 use the create button wizard, to do this declaratively.)
    Regards,
    Marc

  • How to set a bind variable into a vo query from the current vo ?

    I would like to exclude from my list of values defined in a view object the already referenced items in the current view object content.
    Let's say i have dept and emp with a many to many relationships, I would like that the already existing dept for emp not listed (excluded) in the list of values for emp.
    Do i need to define a bind parameters and set it during search or is it possible to use an expression that will refer the current row attribute representing the dept ?
    I didn't find an example or explanation how to set bind parameters defined in a view object query from seach pages or list of values ui components. May be somebody know how to find the info.
    Thank you

    I think that bind variable accessors in the VO class is what you need. You can override the getter method of the bind variable "LocaleCode2" in order to return the first 2 chars from the bind variable "LocaleCode". Have a look at this blog post for details:
    http://jdeveloperandadf.blogspot.com/2011/03/custom-java-bind-variable-in-where.html
    Dimitar

  • How to set default bind variable value to task parameter value

    Hi,
    I 'm implementing a BPEL process with a human task, and I autogenerate the task form. I have a custom sql table that stores opinions, different processes should show different opinios, so my ADF table can only show records related to that process. A custom process number is sent to the task form as a task parameter. How do I use that value as the bind variable default and only value?
    Thanks,
    I.D.

    Hi Shay and thanks for your reply,
    What I want is what you have but without the login page. I tried to start my flow with an action and for some reason it didn't work.
    Is there anything else you can tell me?
    Thanks,
    I.D.
    P.S. I was able to get it to work using the aproach Frank Nimphius described in another post.
    Re: How do I prepopulate a bind variable from a session variable?
    Anyway just out of curiosity could you please tell me if I could have done it your way?
    Thanks a lot,
    I.D.
    Edited by: user8696770 on 5/Ago/2009 7:12

  • Setting VO bind variable programatically

    Hi,
    We have a panel accordion, which has several panels. Depending on panel's name (text attribute) we need to set the underlining VO bind variable to the name value.
    Could someone point to an example of how to do it?

    use [url http://docs.oracle.com/cd/E14571_01/apirefs.1111/e10653/oracle/jbo/server/ViewObjectImpl.html#setNamedWhereClauseParam%28java.lang.String,%20java.lang.Object%29]setNamedWhereClauseParam  method
    also check {message:id=9904521}
    Edited by: M.Jabr on Nov 28, 2011 8:55 AM

  • Setting Component rendered property On Page-Load

    I am using Jdeveloper 11g - fusion- web application.
    What I am trying to do is, onpageload, I am trying to over-ride some default properties of my uiComponents like rendered or read-only programatically.. I was referring to Steve Muench's Example no 60 -
    [http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html] to do this. That is to say, I have a controller for my page-def file which implements the PagePhaseListener. It looks something like
    {color:#ff0000}
    public void beforePhase(PagePhaseEvent pagePhaseEvent) {
    if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
    if (!isPostback()) {
    new AttributeAuthorization().initializeAuth();
    }{color}
    {color:#000000}
    And inside the initializeAuth() method, I get a handle to the current instance of FacesContext, get the context.getViewRoot()
    component tree, iterate on the component tree and call uiComponenet.setRendered(false/true)
    for some components. My problem is, when the page is rendered, the values I have set is not reflecting. But on the next request, ie, if I simply press the commit button on my page, all the components are rendered the way I expect them to...
    I tried doing this in different phases of the life-cycle like PREPARE_RENDER_ID, PREPARE_MODEL etc, in before and after methods, but my page renderes the way I expect it to only on the next request/page submission!!
    {color}
    Edited by: Julian Stephen on Dec 7, 2008 9:05 PM
    Edited by: Julian Stephen on Dec 7, 2008 9:14 PM

    The reason why I do-not want to use a managed bean is that, I want to do this for all the components in my page(It is reasonably big too). So doing this by a managed bean would mean, I need an interface which has as many getter methods as the no of components in the page. Also, we are still in developement which means everytime some-one adds a new component in the page they need to add a new getter method in the interface. Well not just the interface, but also in all the implementing classes...
    The business use-case is that, I have one page in the application which has different levels of visibility(Some components read-only, some not rendered, some editable) based not just on who is logged in but also on other business conditions decided on the page prior to this. So based on these different conditions I build different schemes or themes(I have like 3/4 themes) which decides which components are read-only, which all are editable etc etc... Now I have to apply this 'theme' on to my page :). The way I am trying to do it now, everytime a new component is added, its visibility just need to be set in the property files of different themes.
    Thanks,
    Julian

  • Dynamically assign value to bind variable in a view object before pageload

    I found that it is extreamely hard to find an example to assign the bind variable in View object at runtime using a data attribute defined in Human task activity. Most of the available samples use a Literal value to do the assignment. In my case, I want to dynamically display the content by assigning the data attribute in Human task to the bind variable in view object before a pageload.
    I do not want to bind the view object to some command component to click a button or link in order to make it work (Unnecessary components in my page).
    The issue is how to access the data attribute in Human task in the java code of client interface in AppModule? or is there a way that I can access the data attribute in Groovy script expression of the bind variable? or if I can access the process data object defined in my BPM process to do the assignment at runtime?
    Really need help on the issue, and I cannot believe that it is so hard to accomplish.
    Thank you very much,

    chk this
    Passing default value to bind variable on page load.
    http://adfcodebits.blogspot.com/2010/03/bit-2-setting-bind-variable-value.html

  • Setting bind variable value programmatically for master and child VO's

    Defined following BC:
    Serv VO - Master VO, has Bind_cNum (bind variable)
    ServDetail VO - Child VO, has Bind_cNum2 (bind variable)
    ServViewLink VL - View link between Serv VO & ServDetail VO
    in AMModule Impl have custom WS:
    public List<ViewRowImpl> getMyServices(String cNum)
    List<ViewRowImpl> result = new ArrayList<ViewRowImpl>();
    ViewObjectImpl vo1 = getServ(); //Master VO
    vo1.setNamedWhereClauseParam("Bind_cNum", cNum);
    vo1.setForwardOnly(true);
    ViewObjectImpl vo2 = getServDetail(); //Child VO
    vo2.setNamedWhereClauseParam("Bind_cNum2", cNum);
    vo1.executeQuery();
    while (vo1.hasNext()) {
    result.add((ViewRowImpl)vo1.next());
    return result;
    I am passing same cNum parameter to both Serv VO (Master VO) and ServDetail VO (child VO) as above. (this is in addition to view link bind variable :Id)
    It shows in the logs that it is setting the values correctly:
    <ViewRowSetImpl> <setNamedWhereClauseParam> [382] Serv ViewRowSetImpl.setNamedWhereClauseParam(Bind_cNum, 11771370)
    <ViewRowSetImpl> <setNamedWhereClauseParam> [383] ServDetail ViewRowSetImpl.setNamedWhereClauseParam(Bind_cNum2, 11771370)
    <ViewRowSetImpl> <doSetWhereClauseParam> [383] Serv ViewRowSetImpl.doSetWhereClause(-1, Bind_cNum, 11771370)
    <ViewRowSetImpl> <execute> [385] Serv ViewRowSetImpl.execute caused params to be "un"changed
    <OracleSQLBuilderImpl> <bindParamValue> [394] Binding param "Bind_cNum": 11771370
    <ADFLogger> <addContextData> Execute query
    -- when executing view link
    <ViewRowSetImpl> <setParamValues> [425] ServViewLink_0 ViewRowSetImpl.setParamValues params changed
    <ViewRowSetImpl> <doSetWhereClauseParam> [426] ServViewLink_0 ViewRowSetImpl.doSetWhereClause(-1, Bind_cNum2, null)
    <ViewObjectImpl> <bindParametersForCollection> [436] For RowSet : ServViewLink_0
    <OracleSQLBuilderImpl> <bindParamValue> [437] Binding null of type 12 for "Bind_cNum2"
    <OracleSQLBuilderImpl> <bindParamValue> [438] Binding param "Bind_Id": 5018
    from above log, when ServViewLink_0 is executed, it is changing Bind_cNum2 bind variable to null.
    how can i pass same bind variable value to both Master and Child view objects from AM Impl.java
    Edited by: bsrao on Oct 11, 2012 6:07 PM
    Edited by: bsrao on Oct 11, 2012 6:10 PM
    Edited by: bsrao on Oct 11, 2012 6:12 PM

    Try executing the vo1 query before setting the bind variable for vo2, then execute the vo2 query (if that's what you want to do).

  • About dynamically setting bind variable in LOV View

    Hi,
    I have a LOV VO for an af:SelectOneChoice field in the page.
    The LOV is depended on an SQL statement in which there is a bind variable in the where clause.
    When I open the page, I set the bind variable by using VO.setNamedWhereClauseParam in the prepareSession method in the application module, followed by VO.executeQuery();
    The problem is, the af:SelectOneChoice is blank. Why?
    If I do not use the bind variable in the SQL, I can see rows in the af:SelectOneChoice field.
    When is the proper time to populate the LOV? And where should I put the code for populating the LOV?
    I am sure that the VO is populated, because after I executeQuery, there are many rows in the VO.
    Thanks
    Stephen
    null

    Hi Franky,
    Yes, when I set a default value for the bind variable, everything is OK.
    But I want the bind variable dynamically be set when the AM is initiated. Is there a way to do that?
    Stephen

  • ADF 11g:set bind variable

    Hi All,
    Requirement is to set the value of bind variable of the recursive view object(DynamicTreeMenuVO1) on which my af:tree is based at run time. The value of the bind variable is coming from DynamicMenuVO1Iterator view object at run time("#{rows.displayVal}"), when I am iterating the DynamicMenuVO1Iterator using af:forEach.
    Following code is there on my jspx page:-
    <af:panelAccordion id="acc" discloseMany="false" discloseNone="false">
    <af:forEach items="#{data.view_DynamicGalleryTreePageDef.DynamicMenuVO1Iterator.allRowsInRange}" var="rows">
    <af:showDetailItem text="#{rows.displayVal}" id="sdi1">
    <af:tree value="#{bindings.DynamicTreeMenuVO1.treeModel}" var="node"
    selectionListener="#{bindings.DynamicTreeMenuVO1.treeModel.makeCurrent}"
    rowSelection="single" id="t1">
    <f:facet name="nodeStamp">
    <af:outputText value="#{node}" id="ot1"/>
    </f:facet>
    </af:tree>
    </af:showDetailItem>
    </af:forEach>
    </af:panelAccordion>
    Unable to find how to pass the value #{rows.displayVal} to the bind variable of DynamicTreeMenuVO1 at run time. Please help
    Thanks,
    Vikram

    Will using the groovy expression to set the bind variable value by referencing desired attributes in DynamicMenuVO1Iterator work?
    Can any one can give me the grovvy expression to "*Referencing attributes in other view objects*".
    Any inputs please..........................
    Edited by: Vikram K on Feb 25, 2010 7:23 PM

Maybe you are looking for