Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Report design not valid. Field not found Jasper Reports

Im trying to create a basic jasper report with JRBeanCollectionDataSource. In there im having a list of objects inside the javabean.

public class Course {

    private int id;
    private List<Student> students;
}

Student object looks like

public class Student {

    private String name;
    private int id;
}

I want to print student information inside my report. This is how my jrxml looks like

 <subDataset name="dataset1" uuid="09015d96-ad5a-4fed-aa9e-19d25e02e205">
 <field name="students" class="java.util.List">
  <fieldDescription><![CDATA[students]]></fieldDescription>
 </field>
</subDataset>

<field name="id" class="java.lang.Integer"/>
<field name="students" class="java.util.List"/>
<field name="name" class="java.lang.String"/>

<componentElement>
                <reportElement x="200" 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{students})]]></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{name}]]></textFieldExpression>
                        </textField>

                    </jr:listContents>
                </jr:list>
            </componentElement>

But when i run this im getting

net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 
     1. Field not found : name
Report design not valid : 
     1. Field not found : name

Im a beginner to jasper reports can anyone please tell me what am i doing wrong here. Thanks

like image 847
Dilantha Avatar asked Jun 20 '15 09:06

Dilantha


People also ask

How do you write if condition in Jasper report?

Jasper Reports doesn't support if-else statements when defining variable expressions. Instead you can use the ternary operators {cond} ? {statement 1} : {statement 2}. You can nest this operator inside a Java expression to obtain the desired output based on multiple conditions.

How do I change the number format in Jasper report?

The best way to format in jasper report is to use the pattern attribute on the textField tag. This will keep correct class (Number), when exporting to for example excel, excel can identify it as number and will also apply same pattern.


1 Answers

You have to define the fields before using it.

In your jrxml, you have three field defined students in the subDataSet, id and students. But you haven't defined name and using it in your jrxml and that's why you are getting this exception.

Try defining name, like

<field name="name" class="java.lang.String"/>
like image 188
MKB Avatar answered Sep 28 '22 03:09

MKB