我可以在Jaspersoft Studio 6.2.0中使用lambda表达式吗?

时间:2016-04-19 11:09:20

标签: java-8 jasper-reports

我使用Jaspersoft Studio 6.2.0,并在具有依赖项的maven项目中编译报告:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.2.0</version>
</dependency>   

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.0.0</version>
</dependency>

报告以

为主
JRBeanArrayDataSource beanDS = new JRBeanArrayDataSource(new Incident[]{incident}, false);

我尝试在乐队表达的Print中使用labmda表达式。似乎没有认识到它。表达式是:

$F{actionList} == null || $F{actionList}.stream().allMatch(a -> ActionStatus.COMPLETED.equals(a.getStatus()))

ActionStatus是一个枚举。我得到语法错误,如:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. a cannot be resolved to a variable
    (((java.util.List)field_actionList.getValue()) == null || ((java.util.List)field_actionList.getValue()).stream().allMatch(a -> ActionStatus.COMPLETED.equals(a.getStatus()))) //$JR_EXPR_ID=248$
                                                                                                                           ^
2. Syntax error on token "-", -- expected
    (((java.util.List)field_actionList.getValue()) == null || ((java.util.List)field_actionList.getValue()).stream().allMatch(a -> ActionStatus.COMPLETED.equals(a.getStatus()))) //$JR_EXPR_ID=248$

我也尝试直接使用对象中的方法,如:

this.hasAllActionsCompleted()

执行相同的操作(这是在为报告的DS设置的Incident对象中):

/**
 * Checks if the incident has all actions completed
 * @return true if all actions are completed or none defined, false otherwise
 */
public boolean hasAllActionsCompleted() {
    return actionList == null || actionList.stream().allMatch(a -> ActionStatus.COMPLETED.equals(a.getStatus()));
}

我得到了:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method hasAllActionsCompleted() is undefined for the type Incident_1461053626798_784639
    this.hasAllActionsCompleted() //$JR_EXPR_ID=248$

还有其他办法吗?或者我应该将lambda表达式结果设置为报告的参数(这是一个明显的解决方法,但我希望采用直接方法)?

1 个答案:

答案 0 :(得分:0)

答案是将方法更改为getter,并将其用作字段。 在我的例子中,我将hasAllActionsCompleted更改为isAllActionsCompleted并添加了一个新字段allActionsCompleted作为布尔值。作为一种魅力。谢谢。