Sara Selim
Sara Selim

Reputation: 467

Filter list o objects into servlet context in jsp page

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 ?

Upvotes: 4

Views: 3364

Answers (1)

Sara Selim
Sara Selim

Reputation: 467

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)}" />

Upvotes: 4

Related Questions