2013/11/18 Nick Williams <nicho...@nicholaswilliams.net>: > >> >> Regarding the list() example, >> "map(u -> [u.username, u.firstName, u.lastName])" creates a >> List<Object> with 3 elements and you are asking for "lastName" >> property on that list. > > No, this is not correct. The lambda expression "u -> [u.username, > u.firstName, u.lastName]" RETURNS a List<Object>. But "u" is a User. I am > creating a List<Object> where the first element is the user's username, the > second element is the user's first name, and the third element is the user's > last name. That is completely valid. It is also essentially identical to > Section 2.3.6.4's example "p->[p.name, p.unitPrice]." > >> >> It is no wonder that it results in NumberFormatException. (Whether >> there should be other handling for wrong property name here, I do not >> know. One should look into what resolvers are being used here). > > It should not result in any exception. It should work, because the syntax is > valid, as explained above. :-) >
You apply map() which replaces each user with a list [u.username, u.firstName, u.lastName]. Then you try to apply sorted() to that list. That sorted() fails as it cannot evaluate "u1.lastName.compareTo(u2.lastName)". As I said - provide a simple example. >> >>>>> Section 2.3.6.4 of the specification uses the following example, where a >>>>> LIST literal is used as the right-hand side of the mapping lambda >>>>> expression: >>>>> >>>>> products.stream().filter(p->p.unitPrice >= 10). >>>>> .map(p->[p.name, p.unitPrice]) >>>>> .toList() >>>>> >>>>> I tried to use this exact syntax, as shown in the spec, with my example: >>>>> >>>>> ${users.stream() >>>>> .filter(u -> fn:contains(u.username, '1')) >>>>> .map(u -> [u.username, u.firstName, u.lastName]) >>>>> .sorted((u1, u2) -> u1.lastName.compareTo(u2.lastName) == 0 >>>>> ? u1.firstName.compareTo(u2.firstName) : >>>>> u1.lastName.compareTo(u2.lastName)) >>>>> .toList()} >>>>> >>>>> And now I get this lovely error: >>>>> >>>>> javax.el.ELException: java.lang.NumberFormatException: For input string: >>>>> "lastName" >>>>> javax.el.BeanELResolver.invoke(BeanELResolver.java:185) >>>>> >>>>> org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:147) >>>>> org.apache.el.parser.AstValue.getValue(AstValue.java:158) >>>>> ... >>>>> >> >> Best regards, >> Konstantin Kolinko > > Thanks, > > Nick > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org