Jump to content

Dynamic List in iReport 3.6 with JavaBean datasour


martijnsalm

Recommended Posts

I'm Using iReport 3.6.

I have a JavaBean class which has the following code:

private Collection<String> containerNumber;

  public Collection<String> getContainerNumber()
  {
    return containerNumber;
  }


  public void setContainerNumber(Collection<String> pContainerNumber)
  {
    this.containerNumber = pContainerNumber;
  }

When i let iReport 3.6 read this JavaBean it sees a Collection (which is what i want). But I want to show this collection in my report as a dynamic list/field. So when the setContainNumber sets 1 container number, the report shows 1 container. When the setContainerNumber sets 10 containers, the report shows 10 containers. Underneath my containers in my report, i have more fields, when it shows 10 containers, these fields should drop 10 container spaces. When it shows 1 container, these fields should drop 1 container space.

My question is: How do I show a dynamic list with a Collection of Strings as JavaBean datasource?

Please help me, if you need more information, please let me know!!!

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...

This is a good question.  The problem is how to treat a simple collection of strings as a data source.

Well, here is the solution.

1. set as datasource the special data source JREmptyDatasource(  $F{my_collection}.size() )

This creates an empty data set with the same size of records as the collection.

2. Pass the $F{my_collection} as parameter to the sub dataset (using the data set run of the List).

3. To print the current element of the collection:

$P{my_collection_param}.get( $V{REPORT_COUNT} )

Giulio

Link to comment
Share on other sites

  • 1 year later...

I found this interesting hint from Giulio, unfortunately I can't get this to work. Can anyone help me? Regards

Code:
<?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" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"><property name="ireport.zoom" value="1.0"/><property name="ireport.x" value="0"/><property name="ireport.y" value="0"/><subDataset name="dataset1">    <parameter name="my_collection_param" class="java.util.Collection" isForPrompting="false">        <defaultValueExpression><![CDATA[$P{my_collection}]]></defaultValueExpression>    </parameter></subDataset><parameter name="my_collection" class="java.util.Collection">    <defaultValueExpression><![CDATA["anna"]]></defaultValueExpression></parameter><field name="my_collection" class="java.util.Collection">    <fieldDescription><![CDATA[]]></fieldDescription></field><background>    <band splitType="Stretch"/></background><title>    <band height="79" splitType="Stretch"/></title><pageHeader>    <band height="35" splitType="Stretch"/></pageHeader><columnHeader>    <band height="61" splitType="Stretch"/></columnHeader><detail>    <band height="125" splitType="Stretch">        <componentElement>            <reportElement x="51" y="30" width="400" height="50"/>            <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="dataset1">                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($F{my_collection}.size())]]></dataSourceExpression>                </datasetRun>                <jr:listContents height="50" width="0">                    <textField>                        <reportElement x="159" y="24" width="100" height="20"/>                        <textElement/>                        <textFieldExpression class="java.lang.String"><![CDATA[$P{my_collection_param}.get( $V{REPORT_COUNT} )]]></textFieldExpression>                    </textField>                </jr:listContents>            </jr:list>        </componentElement>    </band></detail><columnFooter>    <band height="45" splitType="Stretch"/></columnFooter><pageFooter>    <band height="54" splitType="Stretch"/></pageFooter><summary>    <band height="42" splitType="Stretch"/></summary>

 

Post Edited by lameth25 at 06/17/2011 04:12

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