Search code examples
grailsgroovygsp

Groovy gsp: merge lists


I am trying to merge many lists into a single list in a gsp. For example:

  1. Class A has a list of class B instances

  2. When i try using the expression: ${a.findAll(some_condition).b} i am getting a list of lists of instances of B

I would like the expression to return a single list, with all instances of b belonging to every a that satisfies some_condition


Solution

  • Can you try:

    ${a.findAll(some_condition).b.flatten()}
    

    That should get you a single list

    ${a.findAll(some_condition).b.flatten().unique()}
    

    Should also remove duplicates