Jasper table and textfields inside the list component with XML datasource

0

I am trying to generate report using Jasper iReport Designer 5.6.0, where is list with table and some textfields. The generated report could look like this:

To do this, I'm using the following XML file as datasource:

<report>
    <persons>
        <person>
            <dateOfBirth>1940-02-01T00:00:00.000Z</dateOfBirth>
            <fullName>Walter White</fullName>
            <address>Albuquerque 87107</address>
        </person>
        <person>
            <dateOfBirth>1989-02-01T00:00:00.000Z</dateOfBirth>
            <fullName>Skyler White</fullName>
            <address>Albuquerque 87107</address>
        </person>
        <person>
            <dateOfBirth>1962-02-01T00:00:00.000Z</dateOfBirth>
            <fullName>Jesse Pinkman</fullName>
            <address>Santa Fé 28</address>
            <companies>
                <company>
                    <nameOfCompany>Company 124</nameOfCompany>
                    <addressOfCompany>Santa Fé 158</addressOfCompany>
                </company>
            </companies>
        </person>
        <person>
            <dateOfBirth>1970-02-01T00:00:00.000Z</dateOfBirth>
            <fullName>Hank Schrader</fullName>
            <address>El Paso 17</address>
            <companies>
                <company>
                    <nameOfCompany>El Paso Company</nameOfCompany>
                    <addressOfCompany>El Paso 28</addressOfCompany>
                </company>
                <company>
                    <nameOfCompany>COMPANY EPC</nameOfCompany>
                    <addressOfCompany>Santa Fé 18</addressOfCompany>
                </company>
            </companies>
        </person>
    </persons>
</report>

And JRXML template:

<?xml version="1.0" encoding="UTF-8"?>
<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="report1_subreport1" pageWidth="756" pageHeight="140" 
              whenNoDataType="BlankPage" columnWidth="756" leftMargin="0" 
              rightMargin="0" topMargin="0" bottomMargin="0" whenResourceMissingType="Error"
              isIgnorePagination="true" uuid="0a5fd60a-c7ea-46b7-a1e6-484cdedee54a">
   <property name="ireport.zoom" value="1.7715610000000022"/>
   <property name="ireport.x" value="0"/>
   <property name="ireport.y" value="0"/>
   <style name="table 3">
      <box>
         <pen lineWidth="1.0" lineColor="#000000"/>
      </box>
   </style>
   <style name="table 3_TH" mode="Opaque">
      <box>
         <pen lineWidth="0.0" lineColor="#000000"/>
      </box>
   </style>
   <style name="table 3_CH" mode="Opaque" backcolor="#FFD0BF">
      <box>
         <pen lineWidth="0.5" lineColor="#000000"/>
      </box>
   </style>
   <style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
      <box>
         <pen lineWidth="0.5" lineColor="#000000"/>
      </box>
   </style>
   <subDataset name="PersonsDataset" uuid="cf4c2515-8d53-4c2a-a6ca-d33257aa8e74">
      <queryString language="xPath">
         <![CDATA[/report/persons/person]]>
      </queryString>
      <field name="dateOfBirth" class="java.lang.String">
         <fieldDescription><![CDATA[dateOfBirth]]></fieldDescription>
      </field>
      <field name="fullName" class="java.lang.String">
         <fieldDescription><![CDATA[fullName]]></fieldDescription>
      </field>
      <field name="address" class="java.lang.String">
         <fieldDescription><![CDATA[address]]></fieldDescription>
      </field>
   </subDataset>
   <subDataset name="CompanyDataset" uuid="80440d3f-8de3-4fe7-8d02-62734435d23d">
      <queryString language="xPath">
         <![CDATA[/report/persons/person/companies/company]]>
      </queryString>
      <field name="nameOfCompany" class="java.lang.String">
         <fieldDescription><![CDATA[nameOfCompany]]></fieldDescription>
      </field>
      <field name="addressOfCompany" class="java.lang.String">
         <fieldDescription><![CDATA[addressOfCompany]]></fieldDescription>
      </field>
   </subDataset>
   <queryString language="xPath">
      <![CDATA[/report]]>
   </queryString>
   <background>
      <band splitType="Stretch"/>
   </background>
   <detail>
      <band height="140" splitType="Stretch">
         <componentElement>
            <reportElement x="1" y="0" width="753" height="140" 
                           uuid="e417d0a1-9945-42e9-b12b-8bf0573c93ba"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" 
                     xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components 
                                         http://jasperreports.sourceforge.net/xsd/components.xsd"
                     printOrder="Vertical">
               <datasetRun subDataset="PersonsDataset" uuid="c0d23173-9df2-452c-9d97-78dee6f766ef">
                  <dataSourceExpression>
                     <![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/persons/person")]]>
                  </dataSourceExpression>
               </datasetRun>
               <jr:listContents height="140" width="753">
                  <staticText>
                     <reportElement mode="Opaque" x="0" y="0" width="100" height="13" 
                                    backcolor="#C0C0C0" 
                                    uuid="21b820ed-d7eb-4c92-a1c7-8b60880bb3b6"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <text><![CDATA[Full name]]></text>
                  </staticText>
                  <staticText>
                     <reportElement mode="Opaque" x="0" y="13" width="100" height="13" 
                                    backcolor="#C0C0C0" 
                                    uuid="1b637cc8-c654-4734-9ee8-debc404931a2"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <text><![CDATA[Address:]]></text>
                  </staticText>
                  <staticText>
                     <reportElement mode="Opaque" x="0" y="26" width="100" height="13" 
                                    backcolor="#C0C0C0" 
                                    uuid="08dc2de1-652a-4cd5-b572-344dbadb3b91"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <text><![CDATA[Date of birth:]]></text>
                  </staticText>
                  <textField>
                     <reportElement x="101" y="0" width="239" height="13" 
                                    uuid="d18bd33c-028a-4cae-8748-e0f5b12faff5"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <textFieldExpression><![CDATA[$F{fullName}]]></textFieldExpression>
                  </textField>
                  <textField>
                     <reportElement x="101" y="13" width="239" height="13" 
                                    uuid="242e9491-3e9b-450c-bbb8-bf7565e67fa6"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
                  </textField>
                  <textField>
                     <reportElement x="101" y="26" width="239" height="13" 
                                    uuid="efe7b9b3-7573-411a-bada-620939ada8dc"/>
                     <box leftPadding="2">
                        <topPen lineWidth="0.75"/>
                        <leftPen lineWidth="0.75"/>
                        <bottomPen lineWidth="0.75"/>
                        <rightPen lineWidth="0.75"/>
                     </box>
                     <textElement verticalAlignment="Middle">
                        <font size="8" pdfEncoding="Cp1250"/>
                     </textElement>
                     <textFieldExpression><![CDATA[$F{dateOfBirth}]]></textFieldExpression>
                  </textField>
                  <componentElement>
                     <reportElement key="NajdenaOsobaTable1" style="table 3" 
                                    stretchType="RelativeToBandHeight" mode="Transparent" x="88" y="56" 
                                    width="645" height="50" isPrintWhenDetailOverflows="true" 
                                    uuid="99480409-009b-4f75-b435-ad99403ddb56"/>
                     <jr:table whenNoDataType="AllSectionsNoDetail">
                        <datasetRun subDataset="CompanyDataset" uuid="cc9ac018-67f1-4011-995c-d95cd30b8ce3">
                           <dataSourceExpression>
                               <![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/persons/person/companies/company")]]>
                           </dataSourceExpression>
                        </datasetRun>
                        <jr:column width="125" uuid="db854a2c-d49e-46ae-a57b-38be7cd8e7f8">
                           <jr:tableHeader style="table 3_TH" height="17" rowSpan="1">
                              <staticText>
                                 <reportElement mode="Opaque" x="0" y="0" width="125" height="17" 
                                                backcolor="#C0C0C0" 
                                                uuid="8ef76d08-af87-4e3b-9436-2f9863275e50"/>
                                 <box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
                                    <pen lineWidth="0.75"/>
                                    <topPen lineWidth="0.75"/>
                                    <leftPen lineWidth="0.75"/>
                                    <bottomPen lineWidth="0.75"/>
                                    <rightPen lineWidth="0.75"/>
                                 </box>
                                 <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" isBold="false" pdfEncoding="Cp1250"/>
                                 </textElement>
                                 <text><![CDATA[Name of Company]]></text>
                              </staticText>
                           </jr:tableHeader>
                           <jr:detailCell style="table 3_TD" height="16" rowSpan="1">
                              <textField isBlankWhenNull="true">
                                 <reportElement x="0" y="0" width="125" height="16" 
                                                isPrintWhenDetailOverflows="true" 
                                                uuid="d1bcdf70-4494-4552-9c84-2c1acf29d5fa"/>
                                 <box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
                                    <pen lineWidth="0.75"/>
                                    <topPen lineWidth="0.75"/>
                                    <leftPen lineWidth="0.75"/>
                                    <bottomPen lineWidth="0.75"/>
                                    <rightPen lineWidth="0.75"/>
                                 </box>
                                 <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" pdfEncoding="Cp1250"/>
                                 </textElement>
                                 <textFieldExpression><![CDATA[$F{nameOfCompany}]]></textFieldExpression>
                              </textField>
                           </jr:detailCell>
                        </jr:column>
                        <jr:column width="160" uuid="db2c69c2-67ce-4de0-b8fc-4f24b969127f">
                           <jr:tableHeader style="table 3_TH" height="17" rowSpan="1">
                              <staticText>
                                 <reportElement mode="Opaque" x="0" y="0" width="160" height="17" 
                                                backcolor="#C0C0C0" 
                                                uuid="80f738f8-58c1-4959-b441-b1a3424e6bd6"/>
                                 <box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
                                    <pen lineWidth="0.75"/>
                                    <topPen lineWidth="0.75"/>
                                    <leftPen lineWidth="0.75"/>
                                    <bottomPen lineWidth="0.75"/>
                                    <rightPen lineWidth="0.75"/>
                                 </box>
                                 <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" pdfEncoding="Cp1250"/>
                                 </textElement>
                                 <text><![CDATA[Address of Company]]></text>
                              </staticText>
                           </jr:tableHeader>
                           <jr:detailCell style="table 3_TD" height="16" rowSpan="1">
                              <textField isBlankWhenNull="true">
                                 <reportElement x="0" y="0" width="160" height="16" 
                                                isPrintWhenDetailOverflows="true" 
                                                uuid="6351ecdf-eb49-4738-bb51-dee451c5761b"/>
                                 <box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
                                    <pen lineWidth="0.75"/>
                                    <topPen lineWidth="0.75"/>
                                    <leftPen lineWidth="0.75"/>
                                    <bottomPen lineWidth="0.75"/>
                                    <rightPen lineWidth="0.75"/>
                                 </box>
                                 <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" pdfEncoding="Cp1250"/>
                                 </textElement>
                                 <textFieldExpression>
                                    <![CDATA[$F{addressOfCompany}]]>
                                 </textFieldExpression>
                              </textField>
                           </jr:detailCell>
                        </jr:column>
                     </jr:table>
                  </componentElement>
               </jr:listContents>
            </jr:list>
         </componentElement>
      </band>
   </detail>
</jasperReport>

And this is what I'm getting as resulting report:

What can I do? Any ideas? Thank you !

rusindes's picture
Joined: Sep 10 2019 - 7:18am
Last seen: 1 week 1 day ago

0 Answers:

No answers yet
Feedback
randomness