Question

I have a controller where i need to fetch the data from more than one domain, combine return to the view. In GSP page am using jquery ajax to call this coltroller.

I created one wrapper class which wraps the data from multiple domain and returned as json. But the json was not proper.

Did anyone faced problem like this. please share any info related to this.

class XYZController {

class XYZData {
    public ArrayList<String> date;
    public ArrayList<String> Name;
}

def getXYZData() {
    ArrayList<String> dateList = XYZDomain.executeQuery("select distinct date from XYZDomain")
    log.info(dateList);

    ArrayList<String> nameList = ABCDomain.executeQuery("select distinct Name from ABCDomain")
    log.info(nameList);

    XYZData data = new XYZData();
    data.date = dateList;
    data.Name = nameList;

    log.info(data)

    render(data as JSON)

    }
}

Thank in advance.

Was it helpful?

Solution

Okey, try this:

def getData(){

   def returnList = [] 
   List <String>list1 = XYZDomain.executeQuery("select distinct date from XYZDomain") 
   List <String>list2 = ABCDomain.executeQuery("select distinct Name from ABCDomain")

   //iterating list
   list1.each {lst->

     def map = [:]     
map.date = lst     
returnList << map

   }

   //iterating list
   list2.each {lst-> 

     def map = [:]

     map.name = lst

     returnList << map

   } 

   render returnList as JSON 

}

That should solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top