У меня есть простой отчет, он имеет несколько строковых параметров, которые получают все данные, которые мне нужны. Строки такие: «1; 2; 3», «боб; джон; мэри». И мне просто нужно показать данные в строках. И это работает на jaspersoft. НО не на jasperserver, когда я запускаю отчет на сервере jaspersoft, он не показывает данные.
Я использую .split(";") для строк и передаю их в arraylist и использую в качестве источника данных для своих подотчетов. Это уродливо, но работает, по крайней мере, на jaspersoft. Но этого просто нет на jasperserver.
Данные поступают из углового проекта и заполняются пользователем. У меня нет этих данных в БД.
Я думаю, что это проблема, связанная с тем, как я использую источник данных в подотчетах, но я не уверен. Я новичок в jaspersoft. Если это не так, как я должен это делать, пожалуйста, скажите об этом, любая помощь приветствуется.
Вот мой код отчета:
<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.13.0.final using JasperReports Library version 6.13.0-46ada4d1be8f3c5985fd0b6146f3ed44caed6f05 -->
<jasperReport xmlns = "http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name = "OcorrenciasBancarias" pageWidth = "595" pageHeight = "842" columnWidth = "555" leftMargin = "20" rightMargin = "20" topMargin = "20" bottomMargin = "20" uuid = "8fbddf4a-554c-4f04-9941-b9e16c98b10d">
<property name = "com.jaspersoft.studio.data.sql.tables" value = ""/>
<property name = "com.jaspersoft.studio.data.defaultdataadapter" value = "RK ERP Devel"/>
<property name = "ireport.jasperserver.url" value = "http://192.168.0.205:11001/jasperserver/"/>
<property name = "ireport.jasperserver.user" value = "jasperadmin"/>
<property name = "ireport.jasperserver.report.resource" value = "/reports/telas/quitacao_multiplas_contas/arquivo_retorno/ocorrenciasBancarias_files/main_jrxml"/>
<property name = "ireport.jasperserver.reportUnit" value = "/reports/telas/quitacao_multiplas_contas/arquivo_retorno/ocorrenciasBancarias"/>
<parameter name = "CLIENTE" class = "java.lang.String"/>
<parameter name = "DOCUMENTO" class = "java.lang.String"/>
<parameter name = "NOSSONUMERO" class = "java.lang.String"/>
<parameter name = "VALOR" class = "java.lang.String"/>
<parameter name = "VENCIMENTO" class = "java.lang.String"/>
<parameter name = "OCORRENCIA" class = "java.lang.String"/>
<parameter name = "CLIENTELIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{CLIENTE}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "DOCUMENTOLIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{DOCUMENTO}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "NOSSONUMEROLIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{NOSSONUMERO}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "VALORLIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{VALOR}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "VENCIMENTOLIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{VENCIMENTO}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "OCORRENCIALIST" class = "java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList($P{OCORRENCIA}.split(";"))]]></defaultValueExpression>
</parameter>
<queryString language = "SQL">
<![CDATA[select 1]]>
</queryString>
<background>
<band splitType = "Stretch"/>
</background>
<pageHeader>
<band height = "40" splitType = "Stretch">
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<textField pattern = "dd/MM/yyyy">
<reportElement positionType = "Float" x = "379" y = "0" width = "80" height = "20" forecolor = "#27272F" uuid = "a29fce94-a139-4d14-b782-9fe95ed43793">
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
</reportElement>
<textElement textAlignment = "Right">
<font size = "8"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<textField pattern = "HH:mm">
<reportElement positionType = "Float" x = "432" y = "0" width = "50" height = "20" forecolor = "#27272F" uuid = "22d51de7-fdb2-4681-a3d4-bc3ba4a4cc65">
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
</reportElement>
<textElement textAlignment = "Right">
<font size = "8"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<frame>
<reportElement positionType = "Float" stretchType = "ContainerHeight" x = "0" y = "20" width = "554" height = "20" isRemoveLineWhenBlank = "true" isPrintInFirstWholeBand = "true" uuid = "58d13352-4653-4587-827c-ea222229bbbe">
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER} == 1)]]></printWhenExpression>
</reportElement>
<frame>
<reportElement positionType = "Float" mode = "Opaque" x = "0" y = "0" width = "554" height = "20" backcolor = "#D9D9D9" uuid = "7199097a-7296-410a-91f4-250495caab85">
<property name = "com.jaspersoft.studio.layout" value = "com.jaspersoft.studio.editor.layout.FreeLayout"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.y" value = "px"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<box leftPadding = "1" bottomPadding = "1" rightPadding = "1">
<pen lineColor = "#9FEDE5"/>
<topPen lineWidth = "0.0" lineStyle = "Solid" lineColor = "#000000"/>
<leftPen lineWidth = "0.0" lineStyle = "Solid" lineColor = "#000000"/>
<bottomPen lineWidth = "0.0" lineStyle = "Solid" lineColor = "#000000"/>
<rightPen lineWidth = "0.0" lineStyle = "Solid" lineColor = "#000000"/>
</box>
<staticText>
<reportElement positionType = "Float" x = "0" y = "0" width = "552" height = "20" forecolor = "#27272F" uuid = "592cfe50-8cc4-473d-bac5-93c67922aedd">
<property name = "com.jaspersoft.studio.unit.height" value = "pixel"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<box topPadding = "1" leftPadding = "1" bottomPadding = "1" rightPadding = "1"/>
<textElement textAlignment = "Center" verticalAlignment = "Middle">
<font size = "10" isBold = "true"/>
</textElement>
<text><![CDATA[INFO FROM PARAMETERS]]></text>
</staticText>
</frame>
</frame>
<textField evaluationTime = "Master">
<reportElement positionType = "Float" x = "442" y = "0" width = "112" height = "20" forecolor = "#27272F" uuid = "921629e5-89b3-4d65-886d-fe20c21fa84b">
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
</reportElement>
<textElement textAlignment = "Right">
<font size = "8"/>
</textElement>
<textFieldExpression><![CDATA["Página "+$V{MASTER_CURRENT_PAGE}+" de "+$V{MASTER_TOTAL_PAGES}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height = "14" splitType = "Stretch">
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<line>
<reportElement x = "0" y = "13" width = "555" height = "1" forecolor = "#595959" uuid = "34831667-1d80-4cae-a91d-d6651c1cf3f4">
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
</reportElement>
</line>
<staticText>
<reportElement x = "0" y = "0" width = "32" height = "14" forecolor = "#27272F" uuid = "549ff20c-f7e6-46b8-b431-d361f478c4a5">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "4a6727e1-e6e7-4a70-8291-1a81b0a10118"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Cliente]]></text>
</staticText>
<staticText>
<reportElement x = "130" y = "0" width = "60" height = "14" forecolor = "#27272F" uuid = "835a1ff7-8ed8-4a88-b5f1-00cd6677957c">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "88aaba7a-4029-4a82-b1c2-ee8e93b1feb2"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Documento]]></text>
</staticText>
<staticText>
<reportElement x = "200" y = "0" width = "70" height = "14" forecolor = "#27272F" uuid = "dd5bfaf9-d080-4499-86f2-a7e0e4d3b492">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "5c2a2b79-9bac-4851-b7b3-c7642b0976ad"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
<property name = "com.jaspersoft.studio.unit.x" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Nosso Número]]></text>
</staticText>
<staticText>
<reportElement x = "280" y = "0" width = "70" height = "14" forecolor = "#27272F" uuid = "33fb80ff-5f98-4c6f-ae62-1695b0b08490">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "d4028cee-3416-4e73-8c8d-56b544671f27"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Valor]]></text>
</staticText>
<staticText>
<reportElement x = "350" y = "0" width = "60" height = "14" forecolor = "#27272F" uuid = "056f347b-d9a2-49ee-8674-8d31e9b07ea8">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "8e8f8fed-a90c-4c5b-b2cc-d0ad1c49dc1a"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Vencimento]]></text>
</staticText>
<staticText>
<reportElement x = "420" y = "0" width = "134" height = "14" forecolor = "#27272F" uuid = "af29b7ba-2bc2-45be-a78a-f70bda792540">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "8e8f8fed-a90c-4c5b-b2cc-d0ad1c49dc1a"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<textElement verticalAlignment = "Middle">
<font size = "8" isBold = "true"/>
</textElement>
<text><![CDATA[Ocorrência]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height = "30" splitType = "Stretch">
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<subreport>
<reportElement x = "0" y = "0" width = "130" height = "30" uuid = "914c099d-14bb-48a7-a696-73973de7093b">
<property name = "com.jaspersoft.studio.unit.y" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
<property name = "com.jaspersoft.studio.unit.width" value = "px"/>
</reportElement>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{CLIENTELIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x = "130" y = "0" width = "70" height = "30" uuid = "924b44a1-81c6-4634-929d-e0ece1e11e2a">
<property name = "com.jaspersoft.studio.unit.y" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
</reportElement>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{DOCUMENTOLIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT_VALOR.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x = "200" y = "0" width = "80" height = "30" uuid = "c957a547-8e5f-4985-83fd-cc7eebbe8568"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{NOSSONUMEROLIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT_NUMERO.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x = "280" y = "0" width = "70" height = "30" uuid = "735a18c3-59ff-425f-9752-4a54a29b7ccf">
<property name = "com.jaspersoft.studio.unit.y" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
</reportElement>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{VALORLIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT_VALOR.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x = "350" y = "0" width = "70" height = "30" uuid = "417264e1-2694-462b-8cdc-a2768c3ef18c"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{VENCIMENTOLIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT_VALOR.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x = "420" y = "0" width = "135" height = "30" uuid = "5b686650-452c-4286-8513-163fa164f3ce">
<property name = "com.jaspersoft.studio.unit.y" value = "px"/>
<property name = "com.jaspersoft.studio.unit.height" value = "px"/>
</reportElement>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{OCORRENCIALIST})]]></dataSourceExpression>
<subreportExpression><![CDATA["SUBREPORT_OCORRENCIA.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Имя поля _THIS. $F{_THIS}. Я не знаю, как это работает.
На сервере можно увидеть основные части отчета? Какой адаптер данных вы используете в Studio? "Одна пустая запись"?
Да, я вижу основные части отчета на сервере. В настоящее время я использую свою базу данных в качестве адаптера данных, я пробовал с одной пустой записью, и она ничего не показала.
Аналогично тому, что вы уже сделали. Но использует один подотчет.
$P{numbers}: 1;2;3
$P{names}: a;b;c
$P{numbersList}: Arrays.asList($P{numbers}.split(";"))
$P{namesList}: Arrays.asList($P{names}.split(";"))
$P{recordsList}: java.util.stream.IntStream.range(0, $P{numbersList}.size()).mapToObj( i -> new String[]{(String)$P{numbersList}.get(i), (String)$P{namesList}.get(i)} ).collect(java.util.stream.Collectors.toList())
Приведенный выше код берет 1-й элемент каждого списка и помещает его в один массив. Затем принимает второй элемент каждого списка и так далее. В итоге у вас есть это:
List[ [1, a], [2, b], [3, c] ]
При вызове подотчета вы передаете этот источник данных:
new net.sf.jasperreports.engine.data.ListOfArrayDataSource(
$P{recordsList},
new String[]{"number", "name"}
)
Очевидно, что в подотчете обязательно должны быть поля number
и name
.
Это сработало для меня в Jaspersoft Studio.
Основной.jrxml:
<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f -->
<jasperReport xmlns = "http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name = "Main" pageWidth = "595" pageHeight = "842" columnWidth = "555" leftMargin = "20" rightMargin = "20" topMargin = "20" bottomMargin = "20" uuid = "acfc3351-2262-463e-ae8a-dd475abdd1bc">
<property name = "com.jaspersoft.studio.data.defaultdataadapter" value = "One Empty Record"/>
<parameter name = "numbers" class = "java.lang.String" isForPrompting = "false">
<defaultValueExpression><![CDATA["1;2;3;4;5;6"]]></defaultValueExpression>
</parameter>
<parameter name = "names" class = "java.lang.String" isForPrompting = "false">
<defaultValueExpression><![CDATA["a;b;c;d;e;f"]]></defaultValueExpression>
</parameter>
<parameter name = "numbersList" class = "java.util.List" nestedType = "java.lang.String" isForPrompting = "false">
<defaultValueExpression><![CDATA[Arrays.asList($P{numbers}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "namesList" class = "java.util.List" nestedType = "java.lang.String" isForPrompting = "false">
<defaultValueExpression><![CDATA[Arrays.asList($P{names}.split(";"))]]></defaultValueExpression>
</parameter>
<parameter name = "recordsList" class = "java.util.List" isForPrompting = "false">
<defaultValueExpression><![CDATA[java.util.stream.IntStream.range(0, $P{numbersList}.size()).mapToObj( i -> new String[]{(String)$P{numbersList}.get(i), (String)$P{namesList}.get(i)} ).collect(java.util.stream.Collectors.toList())]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height = "30">
<textField>
<reportElement x = "0" y = "0" width = "278" height = "30" uuid = "3bde936c-9702-404e-9932-68d37a915600"/>
<textFieldExpression><![CDATA[$P{numbersList}]]></textFieldExpression>
</textField>
<textField>
<reportElement x = "278" y = "0" width = "277" height = "30" uuid = "213c86ad-069a-4bdd-9840-cb71559fa265"/>
<textFieldExpression><![CDATA[$P{namesList}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height = "30" splitType = "Stretch">
<subreport>
<reportElement x = "0" y = "0" width = "555" height = "30" uuid = "8049f4ff-e490-4a1c-8c85-71be6335ba69"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.ListOfArrayDataSource( $P{recordsList}, new String[]{"number", "name"} )]]></dataSourceExpression>
<subreportExpression><![CDATA["Sub.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Sub.jrxml:
<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f -->
<jasperReport xmlns = "http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name = "Sub" pageWidth = "595" pageHeight = "842" columnWidth = "555" leftMargin = "20" rightMargin = "20" topMargin = "20" bottomMargin = "20" uuid = "f06a30d4-cc6b-4ca5-a42f-3dcf791be297">
<property name = "com.jaspersoft.studio.data.defaultdataadapter" value = "NO_DATA_ADAPTER"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name = "number" class = "java.lang.String"/>
<field name = "name" class = "java.lang.String"/>
<columnHeader>
<band height = "30">
<staticText>
<reportElement x = "0" y = "0" width = "278" height = "30" uuid = "3705eb7a-891e-4118-bcad-abae96e78171">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "4faf3089-5386-4350-9b8c-6f2f3eac41f7"/>
</reportElement>
<text><![CDATA[number]]></text>
</staticText>
<staticText>
<reportElement x = "278" y = "0" width = "277" height = "30" uuid = "e194e190-bf9a-4f01-8aef-c2799a240199">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "cf256fba-83b6-4575-9cc7-487a63cfb77b"/>
</reportElement>
<text><![CDATA[name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height = "30" splitType = "Stretch">
<textField>
<reportElement x = "0" y = "0" width = "278" height = "30" uuid = "572c825e-3188-4b27-95e1-b24ac2009d6a">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "4faf3089-5386-4350-9b8c-6f2f3eac41f7"/>
</reportElement>
<textFieldExpression><![CDATA[$F{number}]]></textFieldExpression>
</textField>
<textField>
<reportElement x = "278" y = "0" width = "277" height = "30" uuid = "f1662cf8-13a8-4d5d-b55a-0901b2aabec3">
<property name = "com.jaspersoft.studio.spreadsheet.connectionID" value = "cf256fba-83b6-4575-9cc7-487a63cfb77b"/>
</reportElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Это работало лучше, чем мой код в jasperstudio, но все равно не работало на jasperserver. Я все еще пытаюсь понять, почему он отказывается работать там. Но большое спасибо.
Я предполагаю, что сервер Jasper передает другой источник данных, который переопределяет тот, который вы передаете.
Я не понимаю, как это может работать
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{VENCIMENTOLIST})
. Вы должны предоставить коллекцию bean-компонентов, и вы предоставляете коллекцию строк. Как называются поля ($F) в подотчетах?