Jump to content
We've recently updated our Privacy Statement, available here ×

JRTableModelDataSource question


bdteter

Recommended Posts

I am having some issues geting a Jasper Report to work using a JRTableModelDataSource. 

My data model is a 2-D array of objects.  I have fields setup in the Jasper Report that have the same names as the properies in the object that I want to print (the object has additional properties).  But when I run the report from my application I get a bunch of expections "net.sf.jasperreports.engine.JRException: Unknown column name: name..."

Do I need to put my data in some other format so it is compatible with the JRTableModelDataSource?

Here is the source of the report:

<?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="Test1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="618dbbde-c3fc-4c16-8f15-62e81984ebf9">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <subDataset name="ItemDataset" uuid="be6777b9-595d-4493-a6bb-18162bb69f2c">        <parameter name="ItemDataSource" class="net.sf.jasperreports.engine.data.JRTableModelDataSource"/>        <queryString>            <![CDATA[]]>        </queryString>        <field name="name" class="java.lang.String"/>        <field name="id" class="java.lang.Integer"/>        <field name="location" class="java.lang.String"/>        <field name="width" class="java.lang.Double"/>        <field name="height" class="java.lang.Double"/>        <field name="depth" class="java.lang.Double"/>    </subDataset>    <parameter name="ItemDataSource" class="net.sf.jasperreports.engine.data.JRTableModelDataSource"/>    <queryString>        <![CDATA[]]>    </queryString>    <field name="Field_1" class="java.lang.String"/>    <background>        <band splitType="Stretch"/>    </background>    <detail>        <band height="311" splitType="Stretch">            <componentElement>                <reportElement x="0" y="0" width="555" height="311" uuid="d5df41a5-cfad-4b91-b057-b9b2da3d3411">                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>                </reportElement>                <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="ItemDataset" uuid="149d9908-d2a4-417d-93ac-5b85c2174f52">                        <dataSourceExpression><![CDATA[$P{ItemDataSource}]]></dataSourceExpression>                    </datasetRun>                    <jr:column width="50" uuid="d55637db-12be-4a72-a114-eaebc8db522b">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="50" height="30" uuid="a6ad5b97-3efe-4b71-bb1a-c2f0528ddaee">                                    <property name="com.jaspersoft.studio.element.name" value="ID"/>                                </reportElement>                                <text><![CDATA[iD]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="50" height="30" uuid="03dac38b-7ae1-4b23-acb6-eecb0dce0532"/>                                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="90" uuid="2c8f02c6-3324-416c-8fab-56a620f09f26">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="90" height="30" uuid="792355fe-3604-4304-8660-927e14acda55">                                    <property name="com.jaspersoft.studio.element.name" value="Name"/>                                </reportElement>                                <text><![CDATA[Name]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="90" height="30" uuid="2893721f-ac83-4fb6-9843-f8010efae98d"/>                                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="100" uuid="9432bfc8-5541-4f1d-859c-e4e4746b1cfd">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="100" height="30" uuid="54be0734-6f39-47dc-aad7-86184ca498e7">                                    <property name="com.jaspersoft.studio.element.name" value="Category"/>                                </reportElement>                                <text><![CDATA[Category]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="100" height="30" uuid="c45d1f12-0c3f-4bec-b38b-2d46028c9bf3"/>                                <textFieldExpression><![CDATA[$F{location}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="90" uuid="f5fe3132-2a0d-4fce-8683-cfa38d1f885e">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="90" height="30" uuid="5f76c012-499b-450e-a5ef-58a7569811f4"/>                                <text><![CDATA[Width]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="90" height="30" uuid="168de203-735d-4d60-a56b-a4d3db356ab5"/>                                <textFieldExpression><![CDATA[$F{width}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="90" uuid="9ca4f66b-685d-4849-b67c-147cc3a8cac5">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column5"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="90" height="30" uuid="d9d5de05-ce85-42ea-b064-47cd3c05542a">                                    <property name="com.jaspersoft.studio.element.name" value="Height"/>                                </reportElement>                                <text><![CDATA[Height]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="90" height="30" uuid="052b287a-c551-42cb-9255-95aaadff5323"/>                                <textFieldExpression><![CDATA[$F{height}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="110" uuid="39d55115-6ebc-439b-8310-dfc6865a1e54">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column6"/>                        <jr:tableHeader style="Table_TH" height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="110" height="30" uuid="103246ec-a2de-482a-81f2-1e4fe6ad3c5e">                                    <property name="com.jaspersoft.studio.element.name" value="Depth"/>                                </reportElement>                                <text><![CDATA[Depth]]></text>                            </staticText>                        </jr:tableHeader>                        <jr:detailCell style="Table_TD" height="30">                            <textField>                                <reportElement x="0" y="0" width="110" height="30" uuid="e75188f8-8710-4d68-8ca7-5e37fe347a64"/>                                <textFieldExpression><![CDATA[$F{depth}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                </jr:table>            </componentElement>        </band>    </detail></jasperReport>[/code]

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...