This discussion is archived
11 Replies Latest reply: Jan 20, 2013 11:17 PM by Frank Nimphius RSS

ADF Mobile: Call Methods of DataControl from BackingBean

elmariachi Newbie
Currently Being Moderated
Hi there,

I'm developing an ADF application and try to implement login feature. We already exposed the web service and it is possible to call methods by drag and dropping into amx pages. However i would like to execute the web service method from the backing bean and do some extra work according to return values. How may i call a method of a web service (in the data control) in the backing bean?

Thank you,
  • 1. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    you always go through the WS Dc because the Java version on the mobile does not support JAX-WS proxy calls (will be added when upgrading Java to 1.7). So you create the binding reference to the method to invoke and, in Java call
     ValueExpression ve = AdfmfJavaUtilities.evaluateElExpression("#{bindings.methodbindingName}, Object.class);
     AdfELContext elcontext = AdfmfJavaUtilities.getADFELContext();
     OperationBinding methodBinding = (OperationBinding) ve.getValue(elcontext);
     //add arguments
     methodBinding.getParamsMap().put("argumentName".value);
     ...
     Object result = methodBinding.execute();
    {code}
    
    If the function you call returns a primitive return value then you find it in "result"
    
    Frank                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 2. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    lucbors Oracle ACE
    Currently Being Moderated
    Hi,

    You can also invoke a Method form your datacontrol directly form java.
    If you do that approach you don't even have to add the method binding to your pagedefinition.
    AdfmfJavaUtilities.invokeDataControlMethod("<DatacontrolName>", null, "<methodName>",
                                                                                <ParamNames>, <params>, <paramTypes>);
    You can find the javadoc for that here http://docs.oracle.com/cd/E38668_01/apirefs.111230/e27204/oracle/adfmf/framework/api/AdfmfJavaUtilities.html#invokeDataControlMethod_java_lang_String__java_lang_String__java_lang_String__java_util_List__java_util_List__java_util_List_
    Regards

    Luc
  • 3. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    elmariachi Newbie
    Currently Being Moderated
    For the code fragment that Frank proposes the first line does not take 2 parameters only the ELexpression. Moreover i couldn't be able to run it, is it possible if you may add a sample code with 2 simple string parameters?

    For Luc's way, it seems simpler though my web service returns null all the time which should return a boolean. I put println in the service and observe that invokeDataControlMethod does not actually call the method. I use the sample code provided in the documentation with two simple strings. I suspect if name the webservice correctly? Do i need to write the exact bean id such as abc.mobile.myWebService or only myWebService for the first parameter which is the name of the data control.

    Thank you all for this fruitful comments,
  • 4. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    elmariachi Newbie
    Currently Being Moderated
    lucbors wrote:
    Hi,

    You can also invoke a Method form your datacontrol directly form java.
    If you do that approach you don't even have to add the method binding to your pagedefinition.
    AdfmfJavaUtilities.invokeDataControlMethod("<DatacontrolName>", null, "<methodName>",
    <ParamNames>, <params>, <paramTypes>);
    You can find the javadoc for that here http://docs.oracle.com/cd/E38668_01/apirefs.111230/e27204/oracle/adfmf/framework/api/AdfmfJavaUtilities.html#invokeDataControlMethod_java_lang_String__java_lang_String__java_lang_String__java_util_List__java_util_List__java_util_List_
    Regards

    Luc
    I worked on this solution but not sure if this also works for web service data control because my function always returns null where boolean is expected. Did you also used this function for web services?
  • 5. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    Joe Huang Journeyer
    Currently Being Moderated
    Hi,

    Does this article help?

    https://blogs.oracle.com/mobile/entry/web_services_example_part_2

    Thanks,

    Joe Huang
  • 6. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    elmariachi Newbie
    Currently Being Moderated
    Hi there,

    I saw it a few days ago. Actually it uses AdfmfJavaUtilities.invokeDataControlMethod as i do in my project. The problem is it returns null although the function return type is String. Here is the code fragment that i try to execute.
    List pnames = new ArrayList();
    List params = new ArrayList();
    List ptypes = new ArrayList();
    
    String usr =
         AdfmfJavaUtilities.evaluateELExpression("#{preferenceScope.application.security.userName}").toString();
    String pwd =
         AdfmfJavaUtilities.evaluateELExpression("#{preferenceScope.application.security.password}").toString();
    System.out.println("loginInfo " + "username " + usr + " pass " + pwd);
         
    pnames.add("username");
    ptypes.add(String.class);
    params.add(usr);
    
    pnames.add("password");
    ptypes.add(String.class);
    params.add(pwd);
    
    String isLoginOK = "";
    
    try {
         String resWS;
         resWS =
                AdfmfJavaUtilities.invokeDataControlMethod("myWS", null, "isLogin", pnames, params, ptypes).toString();
                // Note that my web service is under Data Controls. Name of my service is myWS and the functions are directly in this WS.
         if (resWS != null)
              System.out.println("resWS " + resWS.toString() + "  rrr " + resWS.getAttribute(0).toString());
         else
              System.out.println("resWS null"); // Unfortunately this outputs all the time meaning the invokeMethod is not called properly.
                   } catch (AdfInvocationException ex) {
         // If the web service is not available throw a nice exception
         if (AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
              throw new RuntimeException("Error with the server. Please try later.");
         }
    
         return null;
    }
  • 7. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    user404 Pro
    Currently Being Moderated
    I had a simular problem.
    Copying the wsdl file locally solved my problem somehow.
  • 8. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    elmariachi Newbie
    Currently Being Moderated
    Do you copy it using the Create Web Service Control? If yes, i always choose to store WSDL locally.
  • 9. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    Joe Huang Journeyer
    Currently Being Moderated
    Hi,

    Just to confirm - is this a secured Web Services? In the example looks like you are passing ID and password from the user preferences to invoke the web services. That's Ok if the web services is not secured or if you have set up ADF Mobile security separately, and you are simply calling a web services that takes parameters that contains ID/password used for other calls. However, if you are try to actually access a secured web services like this, it would not work. You have to set up the application security and the login screens to set the credential. Once logged in, then the framework itself would embed ID and password in the SOAP header.

    Just confirming security is not the issue here.

    Thanks,

    Joe Huang
  • 10. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    elmariachi Newbie
    Currently Being Moderated
    Hi there,

    No it is not a secured WS. We try to do it in a simple way first.

    I resolved the issue by adding the method under Bindings then invokeDataControlMethod works however this function shouldn't need any bindings to execute the method.
  • 11. Re: ADF Mobile: Call Methods of DataControl from BackingBean
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,


    if the code should run without bindings then the solution suggested by Luc Bors should work:
    AdfmfJavaUtilities.invokeDataControlMethod("<DatacontrolName>", null, "<methodName>",
                                                                                <ParamNames>, <params>, <paramTypes>);
    However, it is important that it is not the data control anme you find in the DataControl.dcx file but the DataBinings.cpx file as this is the registry of data controls used by your project. The easiest way to create the data control entry in this file is to drag a method e.g. as a button and then delete the button. The DataControl entry in teh DataBindings.cpx file will not be removed by this action.

    Frank

Legend

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