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

List with horizontal print order: subreport only on first element of the list rows


ahallez

Recommended Posts

I'm running into a strange problem using the list component in combination a subreport.

The structure of the report is as follows:

1. The main report has a single column layout.

2. The detail band of the report has list component with a horizontal print order. The (fixed) width of the list elements is half the page width, such that each row in the list can contain two elements. The height of the list elements is not fixed.

3. The list element contains a subreport which in turn contains a table component in the detail band.

As it turns out, the report compiles. When executed, the uneven list elements (displayed at the left side of the page) are rendered correctly, but the even list elements, displayed on the right side of the page, are not rendered correctly. I added logging to the datasource classes used in the reports, and it looks like the datasources for the right side list elements are never traversed.

When I switch the printorder to vertical, the content is correct (but not the layout).

Currently I'm out of options for solving this problem.

Any ideas about were to look?

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The data sources used in the report are all custom datasources. The main datasource providing a subdatasource (through a field) for each detail.

In general the list subdatasource contains 0 to many elements. The traversal of this datasource seems to work well.

The list subdatasource is providing a subsdatasource of its own (again through a field) containing only one element. This is the datasource that is not traversed well; it is only used in the list elements that are positioned on the left side and not for the elements positioned on the right side of the page.

 

 

Link to comment
Share on other sites

Ok here goes:

  1. The main report
  2. The subreport
  3. The data source(s) class file
<!DOCTYPE jasperReport [    <!ENTITY fonts SYSTEM "be/gymfed/GymFedFonts.xml">    <!ENTITY parameters SYSTEM "be/gymfed/GymFedDefaultParameters.xml">    <!ENTITY pageheader SYSTEM "be/gymfed/PageHeader.xml">    <!ENTITY pagefooter SYSTEM "be/gymfed/PageFooter.xml">]><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="ParticipantsReport"    columnCount="1"    printOrder="Vertical"    pageWidth="595"    pageHeight="842"    columnWidth="535"    columnSpacing="0"    leftMargin="30"    rightMargin="30"    topMargin="20"    bottomMargin="20"    isTitleNewPage="false"    isSummaryNewPage="false"        scriptletClass="be.scoreexpress.ui.report.SEScriptlet">&fonts;<subDataset name="blocks">  <parameter name="TEMPLATE_FILE" class="java.lang.String" />  <parameter name="blockSubReport" class="java.lang.String" />  <field name="block" class="be.scoreexpress.data.competition.Block"/>  <field name="blockDataSource" class="net.sf.jasperreports.engine.JRDataSource"/></subDataset>&parameters;<parameter name="blockSubReport" class="java.lang.String" /><field name="session" class="java.lang.Object"/><field name="categories" class="java.lang.String"/><field name="blocks" class="net.sf.jasperreports.engine.JRDataSource"/>&pageheader;<detail>  <band height="90">    <textField isStretchWithOverflow="true" >      <reportElement x="0" y="0" width="535" height="22" style="headerbold"        positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"        isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="true"/>      <textElement textAlignment="Left" lineSpacing="Single">        <font size="15"/>      </textElement>      <textFieldExpression class="java.lang.String">        ((be.scoreexpress.data.competition.Session) $F{session}).getName()      </textFieldExpression>    </textField>    <!--<textField isStretchWithOverflow="true" >      <reportElement x="0" y="24" width="535" height="22" style="headerbold"        positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"        isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="true"/>      <textElement textAlignment="Left" lineSpacing="Single"/>      <textFieldExpression class="java.lang.String">        $F{categories}      </textFieldExpression>    </textField>-->    <componentElement>      <reportElement x="0" y="25" width="535" height="65" style="table" />      <c:list        xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"        printOrder="Horizontal">        <datasetRun subDataset="blocks">          <parametersMapExpression>$P{REPORT_PARAMETERS_MAP}</parametersMapExpression>          <!--<datasetParameter name="TEMPLATE_FILE">            <datasetParameterExpression>$P{TEMPLATE_FILE}</datasetParameterExpression>          </datasetParameter>          <datasetParameter name="blockSubReport">            <datasetParameterExpression>$P{blockSubReport}</datasetParameterExpression>          </datasetParameter>-->          <dataSourceExpression>$F{blocks}</dataSourceExpression>        </datasetRun>        <c:listContents height="30" width="266">          <textField isStretchWithOverflow="true" >            <reportElement x="0" y="0" width="265" height="16" style="headerbold"              positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"              isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="true"/>            <textElement textAlignment="Left" lineSpacing="Single">              <font size="13" isBold="true" />            </textElement>            <textFieldExpression class="java.lang.String">              $F{block}.toString();            </textFieldExpression>          </textField>          <subreport isUsingCache="false">            <reportElement x="0" y="25" width="265" height="0" isRemoveLineWhenBlank="true"/>            <!--<subreportParameter name="TEMPLATE_FILE">              <subreportParameterExpression>"./config/GymFedStyles.xml"</subreportParameterExpression>            </subreportParameter>-->            <dataSourceExpression>              $F{blockDataSource}            </dataSourceExpression>            <subreportExpression class="java.lang.String">              $P{blockSubReport}            </subreportExpression>          </subreport>        </c:listContents>      </c:list>    </componentElement>    <!--<subreport isUsingCache="true">      <reportElement positionType="Float" x="0" y="25" width="535" height="0" isRemoveLineWhenBlank="true"/>      <subreportParameter name="TEMPLATE_FILE">        <subreportParameterExpression>$P{TEMPLATE_FILE}</subreportParameterExpression>      </subreportParameter>      <dataSourceExpression>        $F{blocks}      </dataSourceExpression>      <subreportExpression class="java.lang.String">        $P{blockSubReport}      </subreportExpression>    </subreport>-->    <!--<break type="Page">      <reportElement x="0" y="31" width="10" height="1"/>    </break>-->  </band></detail>&pagefooter;</jasperReport>[/code]
<!DOCTYPE jasperReport [    <!ENTITY fonts SYSTEM "be/gymfed/GymFedFonts.xml">]><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="ParticipantsReport"    columnCount="1"    printOrder="Vertical"    pageWidth="265"    pageHeight="100"    columnWidth="265"    columnSpacing="0"    leftMargin="0"    rightMargin="0"    topMargin="0"    bottomMargin="0"    isTitleNewPage="false"    isSummaryNewPage="false" ><template><![CDATA["./config/GymFedStyles.xml"]]></template><subDataset name="blockParticipations">  <field name="blockParticipation" class="be.scoreexpress.data.competition.BlockParticipation"/>  <field name="panel" class="java.lang.String"/></subDataset><!--<parameter name="TEMPLATE_FILE" class="java.lang.String"/>--><!--<field name="block" class="be.scoreexpress.data.competition.Block"/><field name="index" class="java.lang.Integer" />--><field name="blockParticipations" class="net.sf.jasperreports.engine.JRDataSource"/><detail>  <band height="30" ><!--    <textField isStretchWithOverflow="true" >      <reportElement x="0" y="0" width="265" height="16" style="headerbold"        positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"        isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="true"/>      <textElement textAlignment="Left" lineSpacing="Single">        <font size="13" isBold="true" />      </textElement>      <textFieldExpression class="java.lang.String">        $F{block}.toString();      </textFieldExpression>    </textField>-->    <componentElement>      <reportElement x="0" y="0" width="265" height="26" style="table" />      <c:table        xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">        <datasetRun subDataset="blockParticipations">          <dataSourceExpression>$F{blockParticipations}</dataSourceExpression>        </datasetRun>        <c:column width="30">          <c:columnHeader height="16" style="table_TH">            <staticText>              <reportElement x="0" y="0" width="28" height="16" style="transparent">              </reportElement>              <textElement verticalAlignment="Middle">                <font size="10" isBold="true" />              </textElement>              <text>Nr</text>            </staticText>          </c:columnHeader>          <c:detailCell height="26" style="table_TD">            <textField isStretchWithOverflow="true">              <reportElement x="0" y="0" width="28" height="14" style="transparent">              </reportElement>              <textFieldExpression>$F{blockParticipation}.getParticipation().getNumber()</textFieldExpression>            </textField>          </c:detailCell>        </c:column>        <c:column width="110">          <c:columnHeader height="16" style="table_TH">            <staticText>              <reportElement x="0" y="0" width="108" height="16" style="transparent">              </reportElement>              <textElement verticalAlignment="Middle">                <font size="10" isBold="true" />              </textElement>              <text>Participant</text>            </staticText>          </c:columnHeader>          <c:detailCell height="26" style="table_TD">            <textField isStretchWithOverflow="true">              <reportElement x="0" y="0" width="108" height="14" style="transparent">              </reportElement>              <textFieldExpression>$F{blockParticipation}.getParticipation().getParticipantName()</textFieldExpression>            </textField>            <textField isStretchWithOverflow="true">              <reportElement x="0" y="14" width="108" height="12" style="transparent" positionType="Float" isPrintWhenDetailOverflows="true">              </reportElement>              <textElement verticalAlignment="Top">                <font size="7" />              </textElement>              <textFieldExpression>$F{blockParticipation}.getParticipation().getClub().getName()</textFieldExpression>            </textField>          </c:detailCell>        </c:column>        <c:column width="90">          <c:columnHeader height="16" style="table_TH">            <staticText>              <reportElement x="0" y="0" width="88" height="16" style="transparent">              </reportElement>              <textElement verticalAlignment="Middle">                <font size="10" isBold="true" />              </textElement>              <text>Category</text>            </staticText>          </c:columnHeader>          <c:detailCell height="26" style="table_TD">            <textField isStretchWithOverflow="true">              <reportElement x="0" y="0" width="88" height="14" style="transparent">              </reportElement>              <textFieldExpression>$F{blockParticipation}.getParticipation().getCategory().toString()</textFieldExpression>            </textField>          </c:detailCell>        </c:column>      </c:table>    </componentElement>  </band></detail></jasperReport>[/code]
/** To change this template, choose Tools | Templates* and open the template in the editor.*/package be.scoreexpress.ui.report;import be.scoreexpress.data.competition.*;import be.scoreexpress.data.jurypanel.JuryPanel;import java.util.*;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;/**** @author axel*/public class SessionDataSource implements net.sf.jasperreports.engine.JRDataSource {    Iterator<Session> iterator;    Session current;    public SessionDataSource(Competition competition) {        iterator = competition.getSessions().iterator();    }    public boolean next() throws JRException {        if (iterator.hasNext()) {            current = iterator.next();            return true;        }        return false;    }    public Object getFieldValue(JRField jrf) throws JRException {        String name = jrf.getName();        if ("session".equals(name)) {            return current;        }        else if ("categories".equals(name)) {            StringBuilder names = new StringBuilder();            String separator = "";            for (SessionCategory scat : current.getCategories()) {                names.append(separator).append(scat.getCategory().toString());                separator = ", ";            }            return names.toString();        }        else if ("blocks".equals(name)) {            return new BlockDataSource(current);        }        return null;    }}class BlockDataSource implements net.sf.jasperreports.engine.JRRewindableDataSource {    Session session;    Iterator<Block> blockIterator;    Block current = null;    public BlockDataSource(Session session) {        this.session = session;        blockIterator = session.getBlocks().iterator();    }    public boolean next() throws JRException {        java.lang.System.out.println("Next Block 1");        if (blockIterator.hasNext()) {            current = blockIterator.next();            java.lang.System.out.println(current.toString());            return true;        }        return false;    }    public Object getFieldValue(JRField jrf) throws JRException {        if ("block".equals(jrf.getName())) {            return current;        }        else if ("blockDataSource".equals(jrf.getName())) {            return new BlockBlockDataSource(current);        }        return null;    }    public void moveFirst() throws JRException {        current = null;        blockIterator = session.getBlocks().iterator();    }}class BlockBlockDataSource implements net.sf.jasperreports.engine.JRRewindableDataSource {    Block block;    boolean ready = true;    public BlockBlockDataSource(Block block) {        this.block = block;    }    public boolean next() throws JRException {        java.lang.System.out.println("Next Block 2");        if (ready) {            ready = false;            java.lang.System.out.println(block.toString());            return true;        }        return false;    }    public Object getFieldValue(JRField jrf) throws JRException {        if ("blockParticipations".equals(jrf.getName())) {            return new BlockParticipationDataSource(block);        }        return null;    }    public void moveFirst() throws JRException {        ready = true;    }}class BlockParticipationDataSource implements net.sf.jasperreports.engine.JRDataSource {    Iterator<BlockParticipation> partIterator;    BlockParticipation current = null;    public BlockParticipationDataSource(Block block) {        partIterator = block.getParticipations().iterator();    }    public boolean next() throws JRException {        java.lang.System.out.println("Next participation");        if (partIterator.hasNext()) {            current = partIterator.next();            java.lang.System.out.println(current.getParticipation().getParticipantName());            return true;        }        return false;    }    public Object getFieldValue(JRField jrf) throws JRException {        if ("blockParticipation".equals(jrf.getName())) {            return current;        }        if ("panel".equals(jrf.getName())) {            if (current.getEvent() != null) {                JuryPanel panel = JuryPanel.getResponsiblePanel(current.getParticipation(), current.getEvent());                if (panel != null) {                    return panel.getName();                }            }            return "";        }        return null;    }}[/code]

 

 

Link to comment
Share on other sites

  • 1 month later...

For completeness: I upgraded the jasperreports library to 6.0 (from 5.something) and the report renders correctly now.

I still get an expection: Interrupted exception, but this doesn't seem to have an influence on the result.

Link to comment
Share on other sites

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...