Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:18:27+00:00 2026-06-10T15:18:27+00:00

My JavaBean contains the java.util.List . Userinfo { private String username; private String password;

  • 0

My JavaBean contains the java.util.List.

Userinfo {
    private String username;
    private String password;
    List<Address> listAddress;
}

How to show the data of this List in the Detail band?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:18:28+00:00Added an answer on June 10, 2026 at 3:18 pm

    Here is the working sample.

    The key points of this sample:

    • using of the _THIS expression;
    • using List (jr:list) component in Detail band

    The snippet of code for generating report:

    public static void testBuildPdf() {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource());
    
            JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private static JRDataSource getDataSource() {
        Collection<BeanWithList> coll = new ArrayList<BeanWithList>();
        coll.add(new BeanWithList(Arrays.asList("London", "Paris"), 1));
        coll.add(new BeanWithList(Arrays.asList("London", "Madrid", "Moscow"), 2));
        coll.add(new BeanWithList(Arrays.asList("Rome"), 3));
    
        return new JRBeanCollectionDataSource(coll);
    }
    

    The JavaBean code:

    public class BeanWithList {
    
        // The member's name can be any. The JR engine is using public getter for extracting field's value
        private List<String> cities;
        private Integer id;
    
        public BeanWithList(List<String> cities, Integer id) {
            this.cities = cities;
            this.id = id;
        }
    
        // getter should be public    
        public List<String> getCities() {
            return this.cities;
        }
    
        public Integer getId() {
            return this.id;
        }
    }
    

    The jrxml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport ...>
        <subDataset name="dataset1">
            <field name="city" class="java.lang.String">
                <fieldDescription><![CDATA[_THIS]]></fieldDescription>
            </field>
        </subDataset>
        <field name="id" class="java.lang.Integer"/>
        <field name="cities" class="java.util.Collection"/>
        <title>
            <band height="103" splitType="Stretch">
                <staticText>
                    <reportElement x="138" y="28" width="258" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Bean with List sample]]></text>
                </staticText>
            </band>
        </title>
        <columnHeader>
            <band height="20">
                <staticText>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true" isUnderline="false"/>
                    </textElement>
                    <text><![CDATA[Id]]></text>
                </staticText>
                <staticText>
                    <reportElement x="100" y="0" width="100" height="20"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true" isUnderline="false"/>
                    </textElement>
                    <text><![CDATA[City name]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="20" splitType="Stretch">
                <textField>
                    <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                </textField>
                <componentElement>
                    <reportElement x="100" y="0" width="400" height="20"/>
                    <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.data.JRBeanCollectionDataSource($F{cities})]]></dataSourceExpression>
                        </datasetRun>
                        <jr:listContents height="20" width="400">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="20"/>
                                <box leftPadding="10">
                                    <topPen lineWidth="1.0"/>
                                    <leftPen lineWidth="1.0"/>
                                    <bottomPen lineWidth="1.0"/>
                                    <rightPen lineWidth="1.0"/>
                                </box>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
                            </textField>
                        </jr:listContents>
                    </jr:list>
                </componentElement>
            </band>
        </detail>
    </jasperReport>
    

    The result will be:

    The resulting report in PDF format


    Other related questions are the How do I print a list of strings contained within another list in iReport? question and Passing the List of primitive type objects as datasource for subreport question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Spring: In my context.xml, I have: <util:set id=someIDs set-class=java.util.HashSet value-type=java.lang.String> <value>W000000001</value> <value>W000000003</value> <value>W000000009</value> </util:set>
From Spring Projects Issue Tracker Beans: public class JavaBean { private NestedBean nested; }
Sorry this is probably super basic. But in all my javabean examples, I've not
Say I have the following simple java bean: class MyBean { private Date startDate;
I have two db tables. One table contains Forecast data. The second table contains
I use a javaBean in my jsp-application to store form values. This is how
I have an Java bean class Person containing 3 variables: name (String) age (String)
I have two JavaBeans. User Engineer Engineer extends User. User contains this property: public
In the JavaBean section of my revision list it states that I should know
In a Java program, I have a list of beans that I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.