nra_1 Posted March 20, 2019 Share Posted March 20, 2019 Hi! I tried to view data from json data adapter via table element. But table receieves empty dataset when i execute report.Steps i've done.1) I've created http handler that recieves http GET request without parameters or authentification headers and returns json that contains array of objects{ "id": 0, "name": "string", "ord": 0, "visible": true}2) I've created json data adapter in jaspersoft studio3) I've created jasperreport project and blank jasper report.4) I've exported json data adapter as file and placed it into created project5) I've created dataset that uses exported data adapter as datasource wihtout any query6) I've read fields in created dataset(object format is correct on this step)7) I've created table element that takes dataset and use no connection to datasource8) I've opened report preview with json data adapter selected as datasource9) I've got empty report with 3 pages.What should i do to view json array recieved from http handler via table element? Link to comment Share on other sites More sharing options...
narcism Posted March 20, 2019 Share Posted March 20, 2019 Do you really need a table element? Link to comment Share on other sites More sharing options...
nra_1 Posted March 20, 2019 Author Share Posted March 20, 2019 I can use any element, my purpose is to view data from specific data adapter. I also tried to use chart, but both elements get empty data. Link to comment Share on other sites More sharing options...
narcism Posted March 20, 2019 Share Posted March 20, 2019 Please post complete sample JSON data and also mention the version of Jaspersoft Studio Link to comment Share on other sites More sharing options...
nra_1 Posted March 20, 2019 Author Share Posted March 20, 2019 6.6.0.final Community editionjson sample:[ { "id": 1, "name": "item 1", "ord": 1, "visible": true }, { "id": 2, "name": "item 2", "ord": 2, "visible": true }, { "id": 3, "name": "item 3", "ord": 3, "visible": true }, { "id": 4, "name": "item 4", "ord": 4, "visible": true }, { "id": 5, "name": "item 5", "ord": 5, "visible": true }, { "id": 6, "name": "item 6", "ord": 6, "visible": false }] Link to comment Share on other sites More sharing options...
Solution narcism Posted March 20, 2019 Solution Share Posted March 20, 2019 For a basic table-like preview you can just add the fields in the main dataset and get something like:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 --><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="Users" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="61928541-d006-4374-9164-985c6c4116c9"> <queryString language="JSON"> <![CDATA[]]> </queryString> <field name="id" class="java.lang.Integer"> <property name="net.sf.jasperreports.json.field.expression" value="id"/> <fieldDescription><![CDATA[id]]></fieldDescription> </field> <field name="name" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="name"/> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <field name="ord" class="java.lang.Integer"> <property name="net.sf.jasperreports.json.field.expression" value="ord"/> <fieldDescription><![CDATA[ord]]></fieldDescription> </field> <field name="visible" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="visible"/> <fieldDescription><![CDATA[visible]]></fieldDescription> </field> <title> <band height="51"> <staticText> <reportElement x="180" y="0" width="200" height="30" uuid="90b36b64-6fb2-4076-ac5c-f9799d0eace1"/> <textElement textAlignment="Center" verticalAlignment="Justified"> <font size="14"/> </textElement> <text><![CDATA[basic Preview]]></text> </staticText> </band> </title> <columnHeader> <band height="30"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="120" height="30" backcolor="#C2F9FC" uuid="a4247667-3f3f-4154-9dbd-53317fa1b94d"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bd83a66d-284a-45b0-9211-3537ee4a9bb1"/> </reportElement> <text><![CDATA[id]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="120" y="0" width="120" height="30" backcolor="#C2F9FC" uuid="8f508ddb-4f4d-4b31-a39e-2899bc041aac"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="db194b8e-d7c3-4d1d-b052-8591596fdf14"/> </reportElement> <text><![CDATA[name]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="240" y="0" width="120" height="30" backcolor="#C2F9FC" uuid="8eef734b-a06f-4594-8d5f-9ff3a096d3ce"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6fe6e49e-7615-42bd-a8e4-62509007105f"/> </reportElement> <text><![CDATA[ord]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="360" y="0" width="120" height="30" backcolor="#C2F9FC" uuid="a0161638-78ff-4793-9d0e-2fe3c870f95b"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="07c87beb-832f-4b31-b437-db5ec6916e99"/> </reportElement> <text><![CDATA[visible]]></text> </staticText> </band> </columnHeader> <detail> <band height="30"> <textField> <reportElement x="0" y="0" width="120" height="30" uuid="c2d72779-0e0a-429b-aa62-6316d17bc132"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bd83a66d-284a-45b0-9211-3537ee4a9bb1"/> </reportElement> <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> </textField> <textField> <reportElement x="120" y="0" width="120" height="30" uuid="a1847755-6bd5-476f-bfc9-699592d9a7bd"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="db194b8e-d7c3-4d1d-b052-8591596fdf14"/> </reportElement> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> <textField> <reportElement x="240" y="0" width="120" height="30" uuid="2c4acd56-bf85-4479-aa91-0095636faeae"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="6fe6e49e-7615-42bd-a8e4-62509007105f"/> </reportElement> <textFieldExpression><![CDATA[$F{ord}]]></textFieldExpression> </textField> <textField> <reportElement x="360" y="0" width="120" height="30" uuid="e61e5e61-d93d-479f-aa8c-c166fe3e3df3"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="07c87beb-832f-4b31-b437-db5ec6916e99"/> </reportElement> <textFieldExpression><![CDATA[$F{visible}]]></textFieldExpression> </textField> </band> </detail></jasperReport>[/code]If you need to display the data in a subDataset-based element there are some additional steps you need to perform in your case. For a table-based report you could:1. Switch the query language to JSONQL to be able to travel up the JSON tree2. Set the query to select only the first element3. Create a subDataset with the desired fields4. Add a custom dataSourceExpression to your table's datasetRun that moves up the JSON tree and selects the entire arrayYou should be getting something like:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 --><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="Users" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="61928541-d006-4374-9164-985c6c4116c9"> <subDataset name="TableDataset" uuid="773ceda1-586c-40f8-82fd-933dad400bc5"> <field name="id" class="java.lang.Integer"> <property name="net.sf.jasperreports.jsonql.field.expression" value="id"/> <fieldDescription><![CDATA[id]]></fieldDescription> </field> <field name="name" class="java.lang.String"> <property name="net.sf.jasperreports.jsonql.field.expression" value="name"/> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <field name="ord" class="java.lang.Integer"> <property name="net.sf.jasperreports.jsonql.field.expression" value="ord"/> <fieldDescription><![CDATA[ord]]></fieldDescription> </field> <field name="visible" class="java.lang.String"> <property name="net.sf.jasperreports.jsonql.field.expression" value="visible"/> <fieldDescription><![CDATA[visible]]></fieldDescription> </field> </subDataset> <queryString language="JSONQL"> <![CDATA[[0]]]> </queryString> <title> <band height="51"> <staticText> <reportElement x="180" y="0" width="200" height="30" uuid="90b36b64-6fb2-4076-ac5c-f9799d0eace1"/> <textElement textAlignment="Center" verticalAlignment="Justified"> <font size="14"/> </textElement> <text><![CDATA[Table Preview]]></text> </staticText> </band> </title> <columnHeader> <band height="20"/> </columnHeader> <detail> <band height="60"> <componentElement> <reportElement x="0" y="0" width="430" height="60" uuid="d7f20fb3-d6c3-42bd-91b3-e929f6af9e87"/> <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <datasetRun subDataset="TableDataset" uuid="6597a01b-64d4-4286-ae68-f70f31295f2f"> <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("^")]]></dataSourceExpression> </datasetRun> <jr:column width="110" uuid="9805d0a9-fcb9-4ea0-b29e-2fb73ac61cf7"> <jr:columnHeader height="30"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="110" height="30" backcolor="#C2F9FC" uuid="60409ca5-0195-41b4-803c-584434e71927"/> <text><![CDATA[id]]></text> </staticText> </jr:columnHeader> <jr:detailCell height="30"> <textField> <reportElement x="0" y="0" width="110" height="30" uuid="4b178ab7-2a84-4f11-a309-2f830a20d526"/> <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="100" uuid="4c82b871-dacb-4251-9036-952777d48f63"> <jr:columnHeader height="30"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="100" height="30" backcolor="#C2F9FC" uuid="cb5da1fa-a943-4abe-9b33-24d418a101fc"/> <text><![CDATA[name]]></text> </staticText> </jr:columnHeader> <jr:detailCell height="30"> <textField> <reportElement x="0" y="0" width="100" height="30" uuid="811fd3f8-1c69-4f28-82aa-ae820e222870"/> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="110" uuid="5e689a36-a2c3-4426-8949-e2a6ea16fd84"> <jr:columnHeader height="30"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="110" height="30" backcolor="#C2F9FC" uuid="7822f0f3-2532-4f5c-9986-9cd1113cbc50"/> <text><![CDATA[ord]]></text> </staticText> </jr:columnHeader> <jr:detailCell height="30"> <textField> <reportElement x="0" y="0" width="110" height="30" uuid="9de8cef4-1fd6-4185-9f32-fc89f79defba"/> <textFieldExpression><![CDATA[$F{ord}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="110" uuid="cafc6c4f-32e6-4932-872a-e7c1e07cf65e"> <jr:columnHeader height="30"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="110" height="30" backcolor="#C2F9FC" uuid="1cf010d7-f399-4c6b-a027-3696a1f4439b"/> <text><![CDATA[visible]]></text> </staticText> </jr:columnHeader> <jr:detailCell height="30"> <textField> <reportElement x="0" y="0" width="110" height="30" uuid="140206f5-fb7d-4824-8299-6cf1a8e2b5a9"/> <textFieldExpression><![CDATA[$F{visible}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> </jr:table> </componentElement> </band> </detail></jasperReport>[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now