Thursday 21 August 2014

MAF: Data Control method returns Custom Type as array

In my previous post i have discussed about the Call Data control method from managed bean which return the Integer/String or and primitive data type.

But if your Data control method returns the Array of Custom data type Like Employees,Department etc. Use below code.

findEmployeesInDept is data control method which returns array of employees.

        pnames = new ArrayList();
        params = new ArrayList();
        ptypes = new ArrayList();
        
        pnames.add("findCriteria");
        params.add("10");
        ptypes.add(String.class);
       
        //end - WS empty params

        List l = new ArrayList();
        try 
        {    
            GenericType result = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod("HRDC", null, "findEmployeesInDept",pnames, params, ptypes);
            if(result!=null)
            {
                for (int i = 0; i < result.getAttributeCount(); i++) 
                {
                    GenericType r = (GenericType)result.getAttribute(i);
                    Employees wd = (Employees)GenericTypeBeanSerializationHelper.fromGenericType(Employees.class, r);
                    l.add(wd);
                }
            }
        } 
        catch (AdfInvocationException e) 
        {
            e.getMessage();
        }

Thanks
Happy Learning.

2 comments:

  1. Hi Nitesh, thanks for blogging about ADF Mobile & MAF.

    It would be great if you have the time please, to post your new article to the G+ MAF community page: https://plus.google.com/communities/109041800198364610931. This will drive more readers to your blog to read your expert tips, and give you more exposure too if you're keen.

    Keep up the good work, and thanks for posting your ideas to help others.

    Chris Muir.

    ReplyDelete