This discussion is archived
8 Replies Latest reply: Jan 7, 2013 1:04 PM by adfSonal RSS

How to call a method defined in AM when I select any value in LOV

adfSonal Newbie
Currently Being Moderated
Lets say there is a LOV. The scenario is as soon as I select any value in LOV, a method needs to be called which I have written in the AM. And the output of the method is displayed in a output text box.

I am not able to understand how to call a method when the user selects any value in LOV.


This is wht I did. I had created the binding for the method. Changed the autosubmit property of the LOV to True, and in the properties of the output box, in the partial submit trigger property, passed the ID of the LOV. But I didnt get any place where I need to call the method. I am also not able to drop an action listener on the LOV
  • 1. Re: How to call a method defined in AM when I select any value in LOV
    Arunkumar Ramamoorthy Guru
    Currently Being Moderated
    Hi,

    You need to execute the method (by getting the action binding from the binding context) in the valueChangedListener of the LOV.

    -Arun

    P.S : Always mention your JDev version.
  • 2. Re: How to call a method defined in AM when I select any value in LOV
    adfSonal Newbie
    Currently Being Moderated
    No. this is not working.

    v11.1.2.3.0
  • 3. Re: How to call a method defined in AM when I select any value in LOV
    user404 Pro
    Currently Being Moderated
    First of all, bind your output text to your backing bean.
    Add a valueChangeListener from your LOV an add a System.out.print() (or something simular) to test if its works like you want.
    Than, expose your method from your AM to your DataControl. Drag it on your page (so it's binds automaticly) and remove the form/button in your source (so you keep the bindings).
    If the valueChangeListener works like you want, call the AM method in the listener (take a look at this : http://www.adftips.com/2010/10/adf-ui-executing-amimpl-method-in-ui.html).
    Then set the value of your outputtext with the value returned from the AM method (all in the listener method).
  • 4. Re: How to call a method defined in AM when I select any value in LOV
    adfSonal Newbie
    Currently Being Moderated
    Well, I cant see a way by which I can add an action listener to combobox, there is only valuelistener. I created the ADFUtil class... then created a managed bean with this code

    public class TestAMBean {

    public void sampleMethod(ActionEvent actionEvent) {
    /*ADFUtil.invokeEL("#{bindings.methodWithParams.execute}", new Class[] { String.class, String.class },
    new Object[] { "First Param", "Second Param" });*/
    ADFUtil.invokeEL("#{bindings.displayNumberEmployees.execute}", new Class[] { String.class },
    new Object[] { "deptId" });
    }


    but then when I am adding this binding: "#{TestAMBean.sampleMethod}" to valuelistener, its showing an error(underlined in orange).


    Any other way?
  • 5. Re: How to call a method defined in AM when I select any value in LOV
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    +"its showing an error(underlined in orange)."+

    Any reason you don't share this error with us? Anyway, here is how it goes

    1. LOV, set autosubmit="true" and configure a value change listener
    2. Expose the AM method as a method binding in the PageDef file
    3. In the value change listener:
    BindingContext bctx = BindingContxt().getCurrent();
    BindingContainer bindings = bctx.getCurrentBindingsEntry();
    
    OperationBinding method = (OperationBinding) bindings.get("name of method binding in PageDef");
    method.getParamsMap().put("argument name1", value1);
    method.getParamsMap().put("argument name2", value2);
    ...
    Object retVal = method.execute();
    if(!method.getErrors().isEmpty()){
      //handle errors
      ...
    }
    else{
      //write retVal to the managed bean variable that is referenced by the outputText value property
      //PPR output text component
      ADFFacesContext.getCurrentInstance().addPartialTarget(outputTextRef);
    }
    Note that you may have to set clientComponent = "true" on the output text component

    Frank
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 6. Re: How to call a method defined in AM when I select any value in LOV
    939413 Explorer
    Currently Being Moderated
    u need to add a valueChangeListner, and change your method as:
    public void sampleMethod(*ValueChangeEvent valueChange*) {
    //Your code here
    }

    also do keep your combobox autosubmit="true"
  • 7. Re: How to call a method defined in AM when I select any value in LOV
    939413 Explorer
    Currently Being Moderated
    you can also call the method in the am Directly by the code below

    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp =elFactory.createValueExpression(elContext,"#{data." +"*YOUR_DATA_CONTROL_NAME*" +".dataProvider}"",Object.class);
    AppModuleImpl am =(AppModuleImpl)valueExp.getValue(elContext);
                   am.*yourMethodName(param1,param2);*
  • 8. Re: How to call a method defined in AM when I select any value in LOV
    adfSonal Newbie
    Currently Being Moderated
    Wow! Frank, you are great! I was able to complete this small task. Thanks for ur help. You know wht? I hv just started learning this ADF, so I am a newbie. I always have some kind of stupid queries all the time. Even if I read something regarding on ADF on blogs, and then try to implement the same but in a little different way, I always land into some trouble.

    But I have one question. In the LOV, I have included a 'No Selection' item too. But when I run the page, the LOV always display some value. Isnt there any way by which whenever I compile the application, and the page is displayed, I am able to see the blank item first in the LOV?

    Thanks in Advance


    INFACT thanks to everyone who reply to all my queries.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points