我找到了解决我的问题的方法。它可能不是最好的,但它确实有效。我添加了一个参数,它是我创建的 Java 类。它包含一个列表和一个方法,用于接收我需要的字段的 id 和来自 jasper 的页码参数。我用它来建立我的清单。然后在 Jasper 报告中,我有一个标签,仅用于调用我的 bean 中的方法。然后我所要做的就是将索引表放在汇总带中并告诉它从我构建的列表中获取值。在 jasper 中:
<textFieldExpression class="java.lang.String"><![CDATA[$P{indexData}.addByIndex($F{numberInList},$F{indexLabel},$V{PAGE_NUMBER} + "")]]></textFieldExpression>
在 Java 中
public class ReportIndexDataAction {
private List<ReportIndexData> reportIndexDataList;
public ReportIndexDataAction() {
reportIndexDataList = new ArrayList<ReportIndexData>();
}
public List<ReportIndexData> getReportIndexDataList() {
return reportIndexDataList;
}
public void setReportIndexDataList(List<ReportIndexData> reportIndexDataList) {
this.reportIndexDataList = reportIndexDataList;
}
public String addByIndex(int index, String name, String page) {
boolean found = false;
for (Iterator iterator = reportIndexDataList.iterator(); iterator.hasNext();) {
ReportIndexData type = (ReportIndexData) iterator.next();
if(type.getIndex() == index) {
if(!type.getUsages().contains(","+ page + ",")) {
type.setUsages((type.getUsages().isEmpty() ? "," + page +"," : type.getUsages() + page + ","));
}
found = true;
break;
}
}
if(!found) {
ReportIndexData data = new ReportIndexData();
data.setIndex(index);
data.setName(name);
data.setUsages(","+ page + ",");
reportIndexDataList.add(data);
}
return "";
}
和
public class ReportIndexData {
private int index;
private String name;
private String usages;
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsages() {
return usages;
}
public void setUsages(String usages) {
this.usages = usages;
}
}