Hello,
we are facing regression in jasper report version 6.20.0.
For some unknown reason scriptlet is executed twice for element that place in a band that does not fit remaining page size. We did not face with this issue in 6.4.3. Could you please help to resolve this issue. Reproduction path:
public class JasperRepro {
public static void main(String[] args) throws JRException, FileNotFoundException {
JasperDesign myDesign = new JasperDesign();
myDesign.setName("my name");
myDesign.setScriptletClass("CaptionScriptlet");
myDesign.setPageHeight(500);
JRDesignStyle jasperStyle = new JRDesignStyle();
jasperStyle.setName("my style");
jasperStyle.setFontSize(72F);
myDesign.addStyle(jasperStyle);
JRDesignSection details = (JRDesignSection) myDesign.getDetailSection();
JRDesignBand firstPageBand = new JRDesignBand();
firstPageBand.setHeight(300);
details.addBand(firstPageBand);
JRDesignBand secondBand = new JRDesignBand();
//Scriptlet is executed twice when band has SplitTypeEnum.PREVENT split type
secondBand.setSplitType(SplitTypeEnum.PREVENT);
//We expect that elements will be stretched with setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
//Band has 2 elements with TextAdjustEnum.STRETCH_HEIGHT, one of element of them has configured scriptlet
//Defining minimum possible height
secondBand.setHeight(2);
JRDesignTextField element = new JRDesignTextField();
element.setExpression(new JRDesignExpression("\"" + JRStringUtil.escapeJavaStringLiteral("test") + "\""));
//minimal possible height, elements will be stretched with setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
element.setHeight(1);
element.setY(0);
element.setWidth(400);
element.setStyle(jasperStyle);
element.setPositionType(PositionTypeEnum.FLOAT);
element.setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
secondBand.addElement(element);
//Scriptlet which executed twice
String myScriptlet = "((" + CaptionScriptlet.class.getName() + ")$P{REPORT_SCRIPTLET})";
JRDesignTextField elementWithScriptlet = new JRDesignTextField();
elementWithScriptlet.setExpression(new JRDesignExpression(String.format("%s.addCaption(\"%s\")", myScriptlet, "times scriptlet is executed: ")));
//minimal possible height, elements will be stretched with setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
elementWithScriptlet.setHeight(1);
elementWithScriptlet.setWidth(400);
elementWithScriptlet.setY(1);
elementWithScriptlet.setPositionType(PositionTypeEnum.FLOAT);
elementWithScriptlet.setStyle(jasperStyle);
elementWithScriptlet.setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
secondBand.addElement(elementWithScriptlet);
details.addBand(secondBand);
//EXPORT to pdf
JasperReport jasperReport = JasperCompileManager.compileReport(myDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), new JREmptyDataSource());
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new FileOutputStream("c:\\dev\\my.pdf")));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setPermissions(PdfWriter.AllowCopy | PdfWriter.AllowPrinting);
exporter.setConfiguration(configuration);
exporter.exportReport();
}
}
public class CaptionScriptlet extends JRDefaultScriptlet {
private int number = 0;
public String addCaption(String caption) {
return caption + " " + ++number;
}
}