4

I am trying to use lambda expression inside jrxml file to get values for my field.

I imported appropriate classes but it is giving me error that

p cannot be resolved to a variable.

How to use a lambda expression inside JasperReports's templates?.

<textFieldExpression>
    <![CDATA[StringUtils.join(((Collection<Property>)((Object2)$F{field1}.getPropertyValue("property1")).getPropertyValue("property2")).stream().map(p->((Object1)p.getValue()).getName()).collect(toList()),',');]]>
</textFieldExpression>

Exception:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. p cannot be resolved to a variable
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
somename
  • 978
  • 11
  • 30

1 Answers1

5

If you're using the Eclipse JDT compiler, first make sure that you have a fairly recent version.

You can get 4.5.1 from Maven for instance, then add the following properties to your jasperreports.properties file:

org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.source=1.8
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
dada67
  • 4,723
  • 17
  • 19
  • If anyone is having the same issue. I added the eclipse jdt compiler dependency and added jasperreports.properties file with the settings specified at the root level in the resources folder. – somename Jul 11 '16 at 17:47