我想在JasperReport表达式中使用和/或 我尝试了以下但它不起作用:
($P{pId} == $F{id1}) or
($P{pId} == $F{id2} and F{return}=true)
? "good" : "bad"
但我得到以下例外:
Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@1c9f37d net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, calculator_report1_1318247835062_860381: 191: unexpected token: or @ line 191, column 144. 1 error at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:88) at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:188) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215) at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:131) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:509) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
为什么我得到这个例外以及如何解决它的任何想法。
答案 0 :(得分:8)
and
和or
不是有效的Java运算符。 JasperReports使用Java表达式。由于所有Jasper参数和字段都是对象,我怀疑您是否想要将它们与==
进行比较。请改用equals。
($P{pId}.equals($F{id1}) ||
($P{pId}.equals($F{id2}) && F{return}.booleanValue()))
? "good" : "bad"