У меня есть jrxml, и через java я устанавливаю List<List<?>>
в коллекции бинов.Теперь мой окончательный список состоит из 5 списков (может быть и более 5), поэтому jrxml рассматривает все как разные отчеты в одном отчете, и я не могу получить общее количество страниц отчета.Отчет показывает страницу 1-5 для всех 5 отчетов.
Примечание. Я видел несколько ответов, в которых говорится, что нужно получить счет pafe из бэкэнда, но в моем случае это невозможно, поскольку печать на яшме выходит за рамки нашей возможности кодирования.Есть ли способ, которым это может быть достигнуто со стороны JRXML?TIA.
<textField evaluationTime="Master">
<reportElement x="660" y="14" width="58" height="14" forecolor="#1A75B4" uuid="24876562-c6ab-424d-9ac6-769ef9b54079">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Albany WT" size="10"/>
</textElement>
<textFieldExpression><![CDATA["Page " + $V{MASTER_CURRENT_PAGE}]]></textFieldExpression>
</textField>
<textField evaluationTime="Master">
<reportElement x="725" y="14" width="50" height="14" forecolor="#1A75B4" uuid="5c06c90b-79f2-450b-9f43-7eb00676871b">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement textAlignment="Left">
<font fontName="Albany WT" size="10"/>
</textElement>
<textFieldExpression><![CDATA[" of " + $V{MASTER_TOTAL_PAGES}]]></textFieldExpression>
</textField>
Редактировать 2 (добавлен код печати Jasper) Здесь helperReturnObject представляет собой список списка :
List<JasperPrint> prints = new ArrayList<JasperPrint>();
helperReturnObject.getTemPlatepaths().forEach(t -> {
try
{
int index = helperReturnObject.getTemPlatepaths().indexOf(t);
JasperReport jasperReport = null;
if (!developMentFlag)
{
jasperReport = (JasperReport) JRLoader.loadObject(JasperGatewayClass.class.getResourceAsStream(t));
}
else
{
try
{
jasperReport = (JasperReport) JRLoader.loadObject(new FileInputStream(new File("path")));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(
helperReturnObject.getBeanCollections().get(index));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
helperReturnObject.getParameters().get(index), dataSource);
prints.add(jasperPrint);
}
catch (/*JRException | NullPointerException*/ Exception e)
{
System.out.println(e.getMessage() + "----------------------ERROR----------------");
e.printStackTrace();
}
});
Окончательное редактирование Редактировать 3 (Работаем сейчас. Пришлось обновить код, чтобы он работал для полосы заголовка страницы):
for (JasperPrint jp : prints)
{
List<JRPrintPage> pages = jp.getPages();
// Loop all pages of report
for (JRPrintPage jpp : pages)
{
List<JRPrintElement> elements = jpp.getElements();
// Loop all elements on page
for (JRPrintElement jpe : elements)
{
System.out.println(jpe.getClass().getTypeName());
// Check if text element
if (jpe instanceof JRTemplatePrintFrame)
{
JRTemplatePrintFrame jpf = (JRTemplatePrintFrame) jpe;
List<JRPrintElement> jpeElements = jpf.getElements();
for (JRPrintElement jpeElement : jpeElements)
{
if (jpeElement instanceof JRTemplatePrintText)
{
JRTemplatePrintText jpt = (JRTemplatePrintText) jpeElement;
// Check if current page marker
if (CURRENT_PAGE_NUMBER.equals(jpt.getValue()))
{
jpt.setText("Page " + currentPage + " of"); // Replace marker
continue;
}
// Check if total page marker
if (TOTAL_PAGE_NUMBER.equals(jpt.getValue()))
{
jpt.setText(" " + totPageNumber); // Replace marker
}
}
}
}
}
currentPage++;
}
}