Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

java - How to use lambda expression in jrxml file?

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...