This discussion is archived
7 Replies Latest reply: Feb 10, 2013 7:09 PM by 730040 RSS

Oracle ADF Mobile > getting array of objects from webservice

730040 Newbie
Currently Being Moderated
hi,

i am trying to fetch a certain number of records using a webservice call and then storing in the SQLLite DB in the mobile.

i understand i can create a data control using the webservice > then?

my webservice returns an array of objects.

how can i do that?

regards,
ad
  • 1. Re: Oracle ADF Mobile > getting array of objects from webservice
    user404 Pro
    Currently Being Moderated
    It's fairly easy.
    What I have done is created a WebService Controller (plain java class) which calls the methods (from the WS) programmaticly.
    Example :
    public class WSController {
        
        private final String WSDataControllerName = "ThisIsTheNameOfMyWebserviceDataControl";
        
        private List pnames ,ptypes ,params;
        
        public WSController() {
            super();
        }
        
        public List getAllActioncodesFromWS()
        {   
           //start - WS empty params
            pnames = new ArrayList();
            params = new ArrayList();
            ptypes = new ArrayList();
            
            pnames.add("findCriteria");
            params.add(null);
            ptypes.add(Object.class);
            pnames.add("findControl");
            params.add(null);
            ptypes.add(Object.class);
            //end - WS empty params
    
            List actionCodes = new ArrayList();
            try 
            {    
                GenericType result = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod(WSDataControllerName, null, "findActioncodesView1",pnames, params, ptypes);
                if(result!=null)
                {
                    for (int i = 0; i < result.getAttributeCount(); i++) 
                    {
                        GenericType row = (GenericType)result.getAttribute(i);
                        Actioncode wd = (Actioncode)GenericTypeBeanSerializationHelper.fromGenericType(Actioncode.class, row);
                        actionCodes.add(wd);
                    }
                }
            } 
            catch (AdfInvocationException e) 
            {
                e.getMessage();
            }
            catch (Exception e) 
            {
                e.getMessage();
            }
            
         return actionCodes;
        }
    I also defined a Pojo named Actioncode :
    Note that the attribute names are completly the same as the VO from the web service.
    public class Actioncode {
        
        String Actioncode,Descript1;
        
        public Actioncode() {
            super();
        }
    
        public Actioncode(String Actioncode, String Descript1) {
            super();
            this.Actioncode = Actioncode;
            this.Descript1 = Descript1;
        }
    
        public void setActioncode(String Actioncode) {
            this.Actioncode = Actioncode;
        }
    
        public String getActioncode() {
            return Actioncode;
        }
    
        public void setDescript1(String Descript1) {
            this.Descript1 = Descript1;
        }
    
        public String getDescript1() {
            return Descript1;
        }
    }
    Since the WS method returns a GenericType, you can 'convert' that object to an POJO.
    Read more about it here :
    http://adf4beginners.blogspot.be/2013/01/adf-mobile-how-to-iterate-over-all-rows.html
    I know the blog post is about iterating over rows in an iterator, but it's just to illustrate how you can work with the GenericType
  • 2. Re: Oracle ADF Mobile > getting array of objects from webservice
    730040 Newbie
    Currently Being Moderated
    that really helps.
    let me try that and update you.

    regards,
    ad
  • 3. Re: Oracle ADF Mobile > getting array of objects from webservice
    730040 Newbie
    Currently Being Moderated
    i am getting following error in the for loop at below statement,

    GenericType row = (GenericType)result.getAttribute(i);

    error:Java.lang.int

    please help.

    regards,
    ad

    Edited by: user12111278 on Feb 7, 2013 6:20 PM
  • 4. Re: Oracle ADF Mobile > getting array of objects from webservice
    730040 Newbie
    Currently Being Moderated
    i think using the above method we can only get the object, not array of objects?

    regards,
    ad
  • 5. Re: Oracle ADF Mobile > getting array of objects from webservice
    user404 Pro
    Currently Being Moderated
    No.
    GenericType result = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod(WSDataControllerName, null, "findActioncodesView1",pnames, params, ptypes);
    In my case, result contains a list of ActionCode objects who come from my WS.

    I use this code myself, so I'm 100% sure it works.
    Check if result itself is not null.
  • 6. Re: Oracle ADF Mobile > getting array of objects from webservice
    730040 Newbie
    Currently Being Moderated
    here is my scenario-

    1. i have a datacontrol ("employeenams") which returns a list of Employees (i.e. array of String object). so there is only 1 attribute i am expecting this to return subsequently.

    2. then i am using followings,

    GenericType result = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod(WSDataControllerName, null, "getAllEmployeeNames",pnames, params, ptypes);

    here i checked, result is not null

    String[] eNames = new String [30];
    eNames= (String[])result.getAttribute(0);

    i was expecting eNames to get the Array of String object containing the employee names from the "employeenams" DC.

    but this returns me an error java.lang.String

    am i doing anything wrong here?

    regards,
    ad
  • 7. Re: Oracle ADF Mobile > getting array of objects from webservice
    730040 Newbie
    Currently Being Moderated
    yes, that works.
    i was trying that with a non SOAP based data control which is not yet supported.

    thanks for the guidelines.

    regards,
    ad

Legend

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