Skip to content
Advertisement

Spring SPEL collection projection

A simple question on SPEL collection selection.

Look at section 10.5.17 Collection Selection on this page https://docs.spring.io/spring/docs/4.3.10.RELEASE/spring-framework-reference/html/expressions.html

JavaScript

What i need is the selection ‘Serbian’ to come from outside and not be a fixed hard coded String.

Just for arguments sake consider that, we could get it as “selectedNationality” from the same society class from the same page in the link.

Modified class with selectedNationality

JavaScript

New Selection

The new selection SPEL would look like

JavaScript

When we try that the error is that “selectedNationality” is not a part of the Member object.

Does that mean that for collection selection in spring expression language we would need a hard coded String ? If yes does anyone know why ?

Advertisement

Answer

Found out how to do it. So the way is to use variables see 10.5.11 Variables @ [https://docs.spring.io/spring/docs/4.3.10.RELEASE/spring-framework-reference/html/expressions.html][1]

Set Variable

So in our case we wold do this set variable :

JavaScript

New Selection

The new selection SPEL would look like this with #selectedNationality

JavaScript

Works like a charm !

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement