jTableDataSourceModel datalink to iReport gives null










0















for report generating I use IReportDesigner.
Put a table to detailbend1 with only 2 cols, fill the col with field parameter
COLUMN_0 and COLUMN_1 defined in the corresponding table dataset "Zeittab" Fields.



enter image description here



In Java the code should fill the reporttable:



DefaultTableModel tazeit = (DefaultTableModel)jTable2.getModel(); 
JasperReport jasperReport;
JasperPrint jasperPrint;

HashMap<String, Object> parameter = new HashMap<String, Object>();

parameter.put("maschine", jTextField7.getText());

try
jasperReport = JasperCompileManager.compileReport("jrxml/reporttest02.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JRTableModelDataSource(jTable2.getModel()));
JasperViewer.viewReport(jasperPrint, true);

catch (JRException e)
e.printStackTrace();



But it reports only null in both tablecols.



The xml part for the table in IReportDesigner:



 <detail>
<band height="30" splitType="Stretch">
<elementGroup/>
<componentElement>
<reportElement x="20" y="0" width="279" height="30" uuid="16877d28-e650-4f23-9087-937a5f072a21">
<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="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
</datasetRun>
<jr:column width="130" uuid="b25fe72b-f6c7-4a18-add1-50e4a9e951a6">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="130" height="30" uuid="e335c7d7-bbb4-4ea9-adfd-b6bfae26ac9e"/>
<textFieldExpression><![CDATA[$FCOLUMN_0]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="150" uuid="3fc1a8fc-5245-4980-90c4-a27dbe5f46fa">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="150" height="30" uuid="1d6321c6-f2b9-43e7-8814-bd13404cfd79"/>
<textFieldExpression><![CDATA[$FCOLUMN_1]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>


The questions:
Should I make a parameter insert of the "Zeittab" like:



JRDataSource ds = new JRTableModelDataSource(jTable2.getModel());
parameter.put("Zeittab", ds);


I tried this, but there was also null in the report.



There is no error message in Netbeans that gives an hint.



Maybe the fault is in the empty JREmptyDatasource in XML:



<datasetRun subDataset="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
</datasetRun>


How may I solve the datalink between the jTable to the cols in the report?










share|improve this question




























    0















    for report generating I use IReportDesigner.
    Put a table to detailbend1 with only 2 cols, fill the col with field parameter
    COLUMN_0 and COLUMN_1 defined in the corresponding table dataset "Zeittab" Fields.



    enter image description here



    In Java the code should fill the reporttable:



    DefaultTableModel tazeit = (DefaultTableModel)jTable2.getModel(); 
    JasperReport jasperReport;
    JasperPrint jasperPrint;

    HashMap<String, Object> parameter = new HashMap<String, Object>();

    parameter.put("maschine", jTextField7.getText());

    try
    jasperReport = JasperCompileManager.compileReport("jrxml/reporttest02.jrxml");
    jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JRTableModelDataSource(jTable2.getModel()));
    JasperViewer.viewReport(jasperPrint, true);

    catch (JRException e)
    e.printStackTrace();



    But it reports only null in both tablecols.



    The xml part for the table in IReportDesigner:



     <detail>
    <band height="30" splitType="Stretch">
    <elementGroup/>
    <componentElement>
    <reportElement x="20" y="0" width="279" height="30" uuid="16877d28-e650-4f23-9087-937a5f072a21">
    <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="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
    </datasetRun>
    <jr:column width="130" uuid="b25fe72b-f6c7-4a18-add1-50e4a9e951a6">
    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
    <jr:detailCell style="Table_TD" height="30">
    <textField>
    <reportElement x="0" y="0" width="130" height="30" uuid="e335c7d7-bbb4-4ea9-adfd-b6bfae26ac9e"/>
    <textFieldExpression><![CDATA[$FCOLUMN_0]]></textFieldExpression>
    </textField>
    </jr:detailCell>
    </jr:column>
    <jr:column width="150" uuid="3fc1a8fc-5245-4980-90c4-a27dbe5f46fa">
    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
    <jr:detailCell style="Table_TD" height="30">
    <textField>
    <reportElement x="0" y="0" width="150" height="30" uuid="1d6321c6-f2b9-43e7-8814-bd13404cfd79"/>
    <textFieldExpression><![CDATA[$FCOLUMN_1]]></textFieldExpression>
    </textField>
    </jr:detailCell>
    </jr:column>
    </jr:table>
    </componentElement>
    </band>
    </detail>


    The questions:
    Should I make a parameter insert of the "Zeittab" like:



    JRDataSource ds = new JRTableModelDataSource(jTable2.getModel());
    parameter.put("Zeittab", ds);


    I tried this, but there was also null in the report.



    There is no error message in Netbeans that gives an hint.



    Maybe the fault is in the empty JREmptyDatasource in XML:



    <datasetRun subDataset="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
    </datasetRun>


    How may I solve the datalink between the jTable to the cols in the report?










    share|improve this question


























      0












      0








      0








      for report generating I use IReportDesigner.
      Put a table to detailbend1 with only 2 cols, fill the col with field parameter
      COLUMN_0 and COLUMN_1 defined in the corresponding table dataset "Zeittab" Fields.



      enter image description here



      In Java the code should fill the reporttable:



      DefaultTableModel tazeit = (DefaultTableModel)jTable2.getModel(); 
      JasperReport jasperReport;
      JasperPrint jasperPrint;

      HashMap<String, Object> parameter = new HashMap<String, Object>();

      parameter.put("maschine", jTextField7.getText());

      try
      jasperReport = JasperCompileManager.compileReport("jrxml/reporttest02.jrxml");
      jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JRTableModelDataSource(jTable2.getModel()));
      JasperViewer.viewReport(jasperPrint, true);

      catch (JRException e)
      e.printStackTrace();



      But it reports only null in both tablecols.



      The xml part for the table in IReportDesigner:



       <detail>
      <band height="30" splitType="Stretch">
      <elementGroup/>
      <componentElement>
      <reportElement x="20" y="0" width="279" height="30" uuid="16877d28-e650-4f23-9087-937a5f072a21">
      <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="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
      <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
      </datasetRun>
      <jr:column width="130" uuid="b25fe72b-f6c7-4a18-add1-50e4a9e951a6">
      <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
      <jr:detailCell style="Table_TD" height="30">
      <textField>
      <reportElement x="0" y="0" width="130" height="30" uuid="e335c7d7-bbb4-4ea9-adfd-b6bfae26ac9e"/>
      <textFieldExpression><![CDATA[$FCOLUMN_0]]></textFieldExpression>
      </textField>
      </jr:detailCell>
      </jr:column>
      <jr:column width="150" uuid="3fc1a8fc-5245-4980-90c4-a27dbe5f46fa">
      <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
      <jr:detailCell style="Table_TD" height="30">
      <textField>
      <reportElement x="0" y="0" width="150" height="30" uuid="1d6321c6-f2b9-43e7-8814-bd13404cfd79"/>
      <textFieldExpression><![CDATA[$FCOLUMN_1]]></textFieldExpression>
      </textField>
      </jr:detailCell>
      </jr:column>
      </jr:table>
      </componentElement>
      </band>
      </detail>


      The questions:
      Should I make a parameter insert of the "Zeittab" like:



      JRDataSource ds = new JRTableModelDataSource(jTable2.getModel());
      parameter.put("Zeittab", ds);


      I tried this, but there was also null in the report.



      There is no error message in Netbeans that gives an hint.



      Maybe the fault is in the empty JREmptyDatasource in XML:



      <datasetRun subDataset="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
      <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
      </datasetRun>


      How may I solve the datalink between the jTable to the cols in the report?










      share|improve this question
















      for report generating I use IReportDesigner.
      Put a table to detailbend1 with only 2 cols, fill the col with field parameter
      COLUMN_0 and COLUMN_1 defined in the corresponding table dataset "Zeittab" Fields.



      enter image description here



      In Java the code should fill the reporttable:



      DefaultTableModel tazeit = (DefaultTableModel)jTable2.getModel(); 
      JasperReport jasperReport;
      JasperPrint jasperPrint;

      HashMap<String, Object> parameter = new HashMap<String, Object>();

      parameter.put("maschine", jTextField7.getText());

      try
      jasperReport = JasperCompileManager.compileReport("jrxml/reporttest02.jrxml");
      jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JRTableModelDataSource(jTable2.getModel()));
      JasperViewer.viewReport(jasperPrint, true);

      catch (JRException e)
      e.printStackTrace();



      But it reports only null in both tablecols.



      The xml part for the table in IReportDesigner:



       <detail>
      <band height="30" splitType="Stretch">
      <elementGroup/>
      <componentElement>
      <reportElement x="20" y="0" width="279" height="30" uuid="16877d28-e650-4f23-9087-937a5f072a21">
      <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="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
      <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
      </datasetRun>
      <jr:column width="130" uuid="b25fe72b-f6c7-4a18-add1-50e4a9e951a6">
      <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
      <jr:detailCell style="Table_TD" height="30">
      <textField>
      <reportElement x="0" y="0" width="130" height="30" uuid="e335c7d7-bbb4-4ea9-adfd-b6bfae26ac9e"/>
      <textFieldExpression><![CDATA[$FCOLUMN_0]]></textFieldExpression>
      </textField>
      </jr:detailCell>
      </jr:column>
      <jr:column width="150" uuid="3fc1a8fc-5245-4980-90c4-a27dbe5f46fa">
      <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
      <jr:detailCell style="Table_TD" height="30">
      <textField>
      <reportElement x="0" y="0" width="150" height="30" uuid="1d6321c6-f2b9-43e7-8814-bd13404cfd79"/>
      <textFieldExpression><![CDATA[$FCOLUMN_1]]></textFieldExpression>
      </textField>
      </jr:detailCell>
      </jr:column>
      </jr:table>
      </componentElement>
      </band>
      </detail>


      The questions:
      Should I make a parameter insert of the "Zeittab" like:



      JRDataSource ds = new JRTableModelDataSource(jTable2.getModel());
      parameter.put("Zeittab", ds);


      I tried this, but there was also null in the report.



      There is no error message in Netbeans that gives an hint.



      Maybe the fault is in the empty JREmptyDatasource in XML:



      <datasetRun subDataset="Zeittab" uuid="162a78f5-b35f-4eb3-bfc2-73fe9c00adb4">
      <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
      </datasetRun>


      How may I solve the datalink between the jTable to the cols in the report?







      java jasper-reports






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 17 at 20:20









      Alex K

      18.4k1480158




      18.4k1480158










      asked Nov 14 '18 at 10:33









      orgenorgen

      8810




      8810






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I found a solution.
          I explain it with a 3 column table, columns named as material, anzahl, info.



          First of all the declaration in the jasper xml file, init the parameter name:



          <parameter name="MaterialCollection" class="java.util.Collection"/>


          Then the table declaration in the jasper xml file:



          <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="MaterialDataset" uuid="ac99630e-03c5-41d1-a0a5-a054a4ffc607">
          <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($PMaterialCollection)]]></dataSourceExpression>
          </datasetRun>
          <jr:column width="227" uuid="9a486baa-c231-461d-a816-b49e69d0e287">
          <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
          <staticText>
          <reportElement x="3" y="0" width="224" height="14" uuid="1fa2f252-3900-47db-9026-277847285dd4"/>
          <textElement textAlignment="Center" verticalAlignment="Middle">
          <font size="7" isBold="true"/>
          </textElement>
          <text><![CDATA[Material]]></text>
          </staticText>
          </jr:columnHeader>
          <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
          <textField>
          <reportElement x="3" y="0" width="224" height="12" uuid="1a6bf583-a396-49cb-8c36-72fb19c83440"/>
          <textElement verticalAlignment="Middle">
          <font size="7"/>
          </textElement>
          <textFieldExpression><![CDATA[$Fmaterial]]></textFieldExpression>
          </textField>
          </jr:detailCell>
          </jr:column>
          <jr:column width="36" uuid="dea2ad4c-6756-488e-90e7-053d2d3430be">
          <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
          <staticText>
          <reportElement mode="Transparent" x="0" y="0" width="36" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="234a9f2c-c163-4c77-af3a-cac70c258153"/>
          <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
          <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
          <paragraph lineSpacing="Single"/>
          </textElement>
          <text><![CDATA[Anzahl]]></text>
          </staticText>
          </jr:columnHeader>
          <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
          <textField pattern="" isBlankWhenNull="false">
          <reportElement mode="Transparent" x="0" y="0" width="36" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="b7924b73-a0f5-45d7-b175-ece4bdf65799"/>
          <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
          <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
          <paragraph lineSpacing="Single"/>
          </textElement>
          <textFieldExpression><![CDATA[$Fanzahl]]></textFieldExpression>
          </textField>
          </jr:detailCell>
          </jr:column>
          <jr:column width="271" uuid="a098e0f8-8447-413d-8436-cb01dbaebb85">
          <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
          <staticText>
          <reportElement mode="Transparent" x="3" y="0" width="268" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="9d00320e-69cf-4d06-a099-e7c3c3c91344"/>
          <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
          <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
          <paragraph lineSpacing="Single"/>
          </textElement>
          <text><![CDATA[Info]]></text>
          </staticText>
          </jr:columnHeader>
          <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
          <textField pattern="" isBlankWhenNull="false">
          <reportElement mode="Transparent" x="3" y="0" width="268" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="c3101aa2-53ff-4ffe-99ca-b29232bfb6fc"/>
          <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
          <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
          <paragraph lineSpacing="Single"/>
          </textElement>
          <textFieldExpression><![CDATA[$Finfo]]></textFieldExpression>
          </textField>
          </jr:detailCell>
          </jr:column>




          In the javacode I create a class with the column names from the jasper xml declaration:



          public class Materialtabelle implements Serializable 
          public String material;
          public String anzahl;
          public String info;

          public String getMaterial() return material;
          public void setMaterial(String material) this.material = material;
          public String getAnzahl() return anzahl;
          public void setAnzahl(String anzahl) this.anzahl = anzahl;
          public String getInfo() return info;
          public void setInfo(String info) this.info = info;



          Then I fill it with my table data, named ma:



          Materialtabelle matZeile = null;
          Collection matListe=new ArrayList<Materialtabelle>();
          for(int i = 0; i < jTable1.getRowCount(); i++)
          matZeile = new Materialtabelle();
          matZeile.setMaterial(((String)ma.getValueAt(i, 0)) == null ? " " : (String)ma.getValueAt(i, 0));
          matZeile.setAnzahl(((String)ma.getValueAt(i, 1)) == null ? " " : (String)ma.getValueAt(i, 1));
          matZeile.setInfo((String)ma.getValueAt(i, 2) == null ? " " : (String)ma.getValueAt(i, 2));
          matListe.add(matZeile);



          After this, I put the data over a parameter to the report:



          HashMap<String, Object> parameter = new HashMap<String, Object>();
          parameter.put("MaterialCollection", matListe);


          Then call the standard for creating the jasperreport, i use a jasperfile, which is a compiled jasper xml template:



          JasperReport jasperReport;
          JasperPrint jasperPrint;

          jasperReport = (JasperReport) JRLoader.loadObject(new File(syspfad + "reporttest01.jasper"));
          jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JREmptyDataSource());
          JasperViewer.viewReport(jasperPrint, false);





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298117%2fjtabledatasourcemodel-datalink-to-ireport-gives-null%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I found a solution.
            I explain it with a 3 column table, columns named as material, anzahl, info.



            First of all the declaration in the jasper xml file, init the parameter name:



            <parameter name="MaterialCollection" class="java.util.Collection"/>


            Then the table declaration in the jasper xml file:



            <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="MaterialDataset" uuid="ac99630e-03c5-41d1-a0a5-a054a4ffc607">
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($PMaterialCollection)]]></dataSourceExpression>
            </datasetRun>
            <jr:column width="227" uuid="9a486baa-c231-461d-a816-b49e69d0e287">
            <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
            <staticText>
            <reportElement x="3" y="0" width="224" height="14" uuid="1fa2f252-3900-47db-9026-277847285dd4"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
            <font size="7" isBold="true"/>
            </textElement>
            <text><![CDATA[Material]]></text>
            </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
            <textField>
            <reportElement x="3" y="0" width="224" height="12" uuid="1a6bf583-a396-49cb-8c36-72fb19c83440"/>
            <textElement verticalAlignment="Middle">
            <font size="7"/>
            </textElement>
            <textFieldExpression><![CDATA[$Fmaterial]]></textFieldExpression>
            </textField>
            </jr:detailCell>
            </jr:column>
            <jr:column width="36" uuid="dea2ad4c-6756-488e-90e7-053d2d3430be">
            <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
            <staticText>
            <reportElement mode="Transparent" x="0" y="0" width="36" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="234a9f2c-c163-4c77-af3a-cac70c258153"/>
            <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
            <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
            <paragraph lineSpacing="Single"/>
            </textElement>
            <text><![CDATA[Anzahl]]></text>
            </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
            <textField pattern="" isBlankWhenNull="false">
            <reportElement mode="Transparent" x="0" y="0" width="36" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="b7924b73-a0f5-45d7-b175-ece4bdf65799"/>
            <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
            <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
            <paragraph lineSpacing="Single"/>
            </textElement>
            <textFieldExpression><![CDATA[$Fanzahl]]></textFieldExpression>
            </textField>
            </jr:detailCell>
            </jr:column>
            <jr:column width="271" uuid="a098e0f8-8447-413d-8436-cb01dbaebb85">
            <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
            <staticText>
            <reportElement mode="Transparent" x="3" y="0" width="268" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="9d00320e-69cf-4d06-a099-e7c3c3c91344"/>
            <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
            <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
            <paragraph lineSpacing="Single"/>
            </textElement>
            <text><![CDATA[Info]]></text>
            </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
            <textField pattern="" isBlankWhenNull="false">
            <reportElement mode="Transparent" x="3" y="0" width="268" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="c3101aa2-53ff-4ffe-99ca-b29232bfb6fc"/>
            <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
            <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
            <paragraph lineSpacing="Single"/>
            </textElement>
            <textFieldExpression><![CDATA[$Finfo]]></textFieldExpression>
            </textField>
            </jr:detailCell>
            </jr:column>




            In the javacode I create a class with the column names from the jasper xml declaration:



            public class Materialtabelle implements Serializable 
            public String material;
            public String anzahl;
            public String info;

            public String getMaterial() return material;
            public void setMaterial(String material) this.material = material;
            public String getAnzahl() return anzahl;
            public void setAnzahl(String anzahl) this.anzahl = anzahl;
            public String getInfo() return info;
            public void setInfo(String info) this.info = info;



            Then I fill it with my table data, named ma:



            Materialtabelle matZeile = null;
            Collection matListe=new ArrayList<Materialtabelle>();
            for(int i = 0; i < jTable1.getRowCount(); i++)
            matZeile = new Materialtabelle();
            matZeile.setMaterial(((String)ma.getValueAt(i, 0)) == null ? " " : (String)ma.getValueAt(i, 0));
            matZeile.setAnzahl(((String)ma.getValueAt(i, 1)) == null ? " " : (String)ma.getValueAt(i, 1));
            matZeile.setInfo((String)ma.getValueAt(i, 2) == null ? " " : (String)ma.getValueAt(i, 2));
            matListe.add(matZeile);



            After this, I put the data over a parameter to the report:



            HashMap<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("MaterialCollection", matListe);


            Then call the standard for creating the jasperreport, i use a jasperfile, which is a compiled jasper xml template:



            JasperReport jasperReport;
            JasperPrint jasperPrint;

            jasperReport = (JasperReport) JRLoader.loadObject(new File(syspfad + "reporttest01.jasper"));
            jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JREmptyDataSource());
            JasperViewer.viewReport(jasperPrint, false);





            share|improve this answer



























              0














              I found a solution.
              I explain it with a 3 column table, columns named as material, anzahl, info.



              First of all the declaration in the jasper xml file, init the parameter name:



              <parameter name="MaterialCollection" class="java.util.Collection"/>


              Then the table declaration in the jasper xml file:



              <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="MaterialDataset" uuid="ac99630e-03c5-41d1-a0a5-a054a4ffc607">
              <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($PMaterialCollection)]]></dataSourceExpression>
              </datasetRun>
              <jr:column width="227" uuid="9a486baa-c231-461d-a816-b49e69d0e287">
              <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
              <staticText>
              <reportElement x="3" y="0" width="224" height="14" uuid="1fa2f252-3900-47db-9026-277847285dd4"/>
              <textElement textAlignment="Center" verticalAlignment="Middle">
              <font size="7" isBold="true"/>
              </textElement>
              <text><![CDATA[Material]]></text>
              </staticText>
              </jr:columnHeader>
              <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
              <textField>
              <reportElement x="3" y="0" width="224" height="12" uuid="1a6bf583-a396-49cb-8c36-72fb19c83440"/>
              <textElement verticalAlignment="Middle">
              <font size="7"/>
              </textElement>
              <textFieldExpression><![CDATA[$Fmaterial]]></textFieldExpression>
              </textField>
              </jr:detailCell>
              </jr:column>
              <jr:column width="36" uuid="dea2ad4c-6756-488e-90e7-053d2d3430be">
              <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
              <staticText>
              <reportElement mode="Transparent" x="0" y="0" width="36" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="234a9f2c-c163-4c77-af3a-cac70c258153"/>
              <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
              <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
              <paragraph lineSpacing="Single"/>
              </textElement>
              <text><![CDATA[Anzahl]]></text>
              </staticText>
              </jr:columnHeader>
              <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
              <textField pattern="" isBlankWhenNull="false">
              <reportElement mode="Transparent" x="0" y="0" width="36" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="b7924b73-a0f5-45d7-b175-ece4bdf65799"/>
              <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
              <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
              <paragraph lineSpacing="Single"/>
              </textElement>
              <textFieldExpression><![CDATA[$Fanzahl]]></textFieldExpression>
              </textField>
              </jr:detailCell>
              </jr:column>
              <jr:column width="271" uuid="a098e0f8-8447-413d-8436-cb01dbaebb85">
              <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
              <staticText>
              <reportElement mode="Transparent" x="3" y="0" width="268" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="9d00320e-69cf-4d06-a099-e7c3c3c91344"/>
              <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
              <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
              <paragraph lineSpacing="Single"/>
              </textElement>
              <text><![CDATA[Info]]></text>
              </staticText>
              </jr:columnHeader>
              <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
              <textField pattern="" isBlankWhenNull="false">
              <reportElement mode="Transparent" x="3" y="0" width="268" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="c3101aa2-53ff-4ffe-99ca-b29232bfb6fc"/>
              <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
              <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
              <paragraph lineSpacing="Single"/>
              </textElement>
              <textFieldExpression><![CDATA[$Finfo]]></textFieldExpression>
              </textField>
              </jr:detailCell>
              </jr:column>




              In the javacode I create a class with the column names from the jasper xml declaration:



              public class Materialtabelle implements Serializable 
              public String material;
              public String anzahl;
              public String info;

              public String getMaterial() return material;
              public void setMaterial(String material) this.material = material;
              public String getAnzahl() return anzahl;
              public void setAnzahl(String anzahl) this.anzahl = anzahl;
              public String getInfo() return info;
              public void setInfo(String info) this.info = info;



              Then I fill it with my table data, named ma:



              Materialtabelle matZeile = null;
              Collection matListe=new ArrayList<Materialtabelle>();
              for(int i = 0; i < jTable1.getRowCount(); i++)
              matZeile = new Materialtabelle();
              matZeile.setMaterial(((String)ma.getValueAt(i, 0)) == null ? " " : (String)ma.getValueAt(i, 0));
              matZeile.setAnzahl(((String)ma.getValueAt(i, 1)) == null ? " " : (String)ma.getValueAt(i, 1));
              matZeile.setInfo((String)ma.getValueAt(i, 2) == null ? " " : (String)ma.getValueAt(i, 2));
              matListe.add(matZeile);



              After this, I put the data over a parameter to the report:



              HashMap<String, Object> parameter = new HashMap<String, Object>();
              parameter.put("MaterialCollection", matListe);


              Then call the standard for creating the jasperreport, i use a jasperfile, which is a compiled jasper xml template:



              JasperReport jasperReport;
              JasperPrint jasperPrint;

              jasperReport = (JasperReport) JRLoader.loadObject(new File(syspfad + "reporttest01.jasper"));
              jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JREmptyDataSource());
              JasperViewer.viewReport(jasperPrint, false);





              share|improve this answer

























                0












                0








                0







                I found a solution.
                I explain it with a 3 column table, columns named as material, anzahl, info.



                First of all the declaration in the jasper xml file, init the parameter name:



                <parameter name="MaterialCollection" class="java.util.Collection"/>


                Then the table declaration in the jasper xml file:



                <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="MaterialDataset" uuid="ac99630e-03c5-41d1-a0a5-a054a4ffc607">
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($PMaterialCollection)]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="227" uuid="9a486baa-c231-461d-a816-b49e69d0e287">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement x="3" y="0" width="224" height="14" uuid="1fa2f252-3900-47db-9026-277847285dd4"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="7" isBold="true"/>
                </textElement>
                <text><![CDATA[Material]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField>
                <reportElement x="3" y="0" width="224" height="12" uuid="1a6bf583-a396-49cb-8c36-72fb19c83440"/>
                <textElement verticalAlignment="Middle">
                <font size="7"/>
                </textElement>
                <textFieldExpression><![CDATA[$Fmaterial]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>
                <jr:column width="36" uuid="dea2ad4c-6756-488e-90e7-053d2d3430be">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement mode="Transparent" x="0" y="0" width="36" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="234a9f2c-c163-4c77-af3a-cac70c258153"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Anzahl]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField pattern="" isBlankWhenNull="false">
                <reportElement mode="Transparent" x="0" y="0" width="36" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="b7924b73-a0f5-45d7-b175-ece4bdf65799"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$Fanzahl]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>
                <jr:column width="271" uuid="a098e0f8-8447-413d-8436-cb01dbaebb85">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement mode="Transparent" x="3" y="0" width="268" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="9d00320e-69cf-4d06-a099-e7c3c3c91344"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Info]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField pattern="" isBlankWhenNull="false">
                <reportElement mode="Transparent" x="3" y="0" width="268" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="c3101aa2-53ff-4ffe-99ca-b29232bfb6fc"/>
                <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$Finfo]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>




                In the javacode I create a class with the column names from the jasper xml declaration:



                public class Materialtabelle implements Serializable 
                public String material;
                public String anzahl;
                public String info;

                public String getMaterial() return material;
                public void setMaterial(String material) this.material = material;
                public String getAnzahl() return anzahl;
                public void setAnzahl(String anzahl) this.anzahl = anzahl;
                public String getInfo() return info;
                public void setInfo(String info) this.info = info;



                Then I fill it with my table data, named ma:



                Materialtabelle matZeile = null;
                Collection matListe=new ArrayList<Materialtabelle>();
                for(int i = 0; i < jTable1.getRowCount(); i++)
                matZeile = new Materialtabelle();
                matZeile.setMaterial(((String)ma.getValueAt(i, 0)) == null ? " " : (String)ma.getValueAt(i, 0));
                matZeile.setAnzahl(((String)ma.getValueAt(i, 1)) == null ? " " : (String)ma.getValueAt(i, 1));
                matZeile.setInfo((String)ma.getValueAt(i, 2) == null ? " " : (String)ma.getValueAt(i, 2));
                matListe.add(matZeile);



                After this, I put the data over a parameter to the report:



                HashMap<String, Object> parameter = new HashMap<String, Object>();
                parameter.put("MaterialCollection", matListe);


                Then call the standard for creating the jasperreport, i use a jasperfile, which is a compiled jasper xml template:



                JasperReport jasperReport;
                JasperPrint jasperPrint;

                jasperReport = (JasperReport) JRLoader.loadObject(new File(syspfad + "reporttest01.jasper"));
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JREmptyDataSource());
                JasperViewer.viewReport(jasperPrint, false);





                share|improve this answer













                I found a solution.
                I explain it with a 3 column table, columns named as material, anzahl, info.



                First of all the declaration in the jasper xml file, init the parameter name:



                <parameter name="MaterialCollection" class="java.util.Collection"/>


                Then the table declaration in the jasper xml file:



                <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="MaterialDataset" uuid="ac99630e-03c5-41d1-a0a5-a054a4ffc607">
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($PMaterialCollection)]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="227" uuid="9a486baa-c231-461d-a816-b49e69d0e287">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement x="3" y="0" width="224" height="14" uuid="1fa2f252-3900-47db-9026-277847285dd4"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="7" isBold="true"/>
                </textElement>
                <text><![CDATA[Material]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField>
                <reportElement x="3" y="0" width="224" height="12" uuid="1a6bf583-a396-49cb-8c36-72fb19c83440"/>
                <textElement verticalAlignment="Middle">
                <font size="7"/>
                </textElement>
                <textFieldExpression><![CDATA[$Fmaterial]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>
                <jr:column width="36" uuid="dea2ad4c-6756-488e-90e7-053d2d3430be">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement mode="Transparent" x="0" y="0" width="36" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="234a9f2c-c163-4c77-af3a-cac70c258153"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Anzahl]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField pattern="" isBlankWhenNull="false">
                <reportElement mode="Transparent" x="0" y="0" width="36" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="b7924b73-a0f5-45d7-b175-ece4bdf65799"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$Fanzahl]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>
                <jr:column width="271" uuid="a098e0f8-8447-413d-8436-cb01dbaebb85">
                <jr:columnHeader style="table 15_CH" height="14" rowSpan="1">
                <staticText>
                <reportElement mode="Transparent" x="3" y="0" width="268" height="14" forecolor="#000000" backcolor="#FFFFFF" uuid="9d00320e-69cf-4d06-a099-e7c3c3c91344"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[Info]]></text>
                </staticText>
                </jr:columnHeader>
                <jr:detailCell style="table 15_TD" height="12" rowSpan="1">
                <textField pattern="" isBlankWhenNull="false">
                <reportElement mode="Transparent" x="3" y="0" width="268" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="c3101aa2-53ff-4ffe-99ca-b29232bfb6fc"/>
                <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
                <font fontName="SansSerif" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
                <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$Finfo]]></textFieldExpression>
                </textField>
                </jr:detailCell>
                </jr:column>




                In the javacode I create a class with the column names from the jasper xml declaration:



                public class Materialtabelle implements Serializable 
                public String material;
                public String anzahl;
                public String info;

                public String getMaterial() return material;
                public void setMaterial(String material) this.material = material;
                public String getAnzahl() return anzahl;
                public void setAnzahl(String anzahl) this.anzahl = anzahl;
                public String getInfo() return info;
                public void setInfo(String info) this.info = info;



                Then I fill it with my table data, named ma:



                Materialtabelle matZeile = null;
                Collection matListe=new ArrayList<Materialtabelle>();
                for(int i = 0; i < jTable1.getRowCount(); i++)
                matZeile = new Materialtabelle();
                matZeile.setMaterial(((String)ma.getValueAt(i, 0)) == null ? " " : (String)ma.getValueAt(i, 0));
                matZeile.setAnzahl(((String)ma.getValueAt(i, 1)) == null ? " " : (String)ma.getValueAt(i, 1));
                matZeile.setInfo((String)ma.getValueAt(i, 2) == null ? " " : (String)ma.getValueAt(i, 2));
                matListe.add(matZeile);



                After this, I put the data over a parameter to the report:



                HashMap<String, Object> parameter = new HashMap<String, Object>();
                parameter.put("MaterialCollection", matListe);


                Then call the standard for creating the jasperreport, i use a jasperfile, which is a compiled jasper xml template:



                JasperReport jasperReport;
                JasperPrint jasperPrint;

                jasperReport = (JasperReport) JRLoader.loadObject(new File(syspfad + "reporttest01.jasper"));
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, new JREmptyDataSource());
                JasperViewer.viewReport(jasperPrint, false);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 5 '18 at 15:25









                orgenorgen

                8810




                8810



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298117%2fjtabledatasourcemodel-datalink-to-ireport-gives-null%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    政党