Pma
Pma

Reputation: 1093

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

Upvotes: 2

Views: 778

Answers (1)

tim_yates
tim_yates

Reputation: 171074

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

Upvotes: 2

Related Questions