Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter list o objects into servlet context in jsp page

Tags:

java

jsp

servlets

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 ?

like image 291
Sara Selim Avatar asked Oct 19 '25 02:10

Sara Selim


1 Answers

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)}" />
like image 62
Sara Selim Avatar answered Oct 21 '25 16:10

Sara Selim