I have a list of object into the application context and I want to filter this list to get only one element to display jsp page. I tried to filter the list using a stream-filter function:
<c:set var="itemDetalias" value="${applicationScope.productList.stream().filter(p -> p.getId() == item.getProductId()).collect(java.util.stream.Collectors.toList()).get(0)}" />
but I have this error msg:
${applicationScope.productList.stream().filter( ppp -> ppp.getId() == item.getProductId()).collect(java.util.stream.Collectors.toList()).get(0)}'
Method not found: class org.apache.el.stream.Stream.collect(null)
How could I filter the list ?
I have found a solution. Tomcat has its own stream library which has some functions like filter, but it does not have collect function. Instead of using the collect function, use the toList function.
The new line should be:
<c:set var="itemDetalias" value="${applicationScope.productList.stream().filter(p -> p.getId() == item.getProductId()).toList().get(0)}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With