How do we access parameters of a bean in Jasper Reports?

前端 未结 1 1415
一向
一向 2021-02-06 17:44

How do we access parameters of a bean in Jasper Reports?

I have to display the data of a model (which is not a collection) in Jasper Reports.

I pass the model t

相关标签:
1条回答
  • 2021-02-06 18:33

    There are a couple steps to accomplish this.

    1) Define your parameter: This will be the full package and class name of the type of the parameter. Something like:

    <parameter name="object" class="com.mystuff.User"/>
    

    2) Call the getter method for the value you want: Add a textfield to the appropriate field. If I wanted to use the value for the method getId() in my User class I my textfield would look like:

    <textField>
        <reportElement uuid="09bf47a8-8fc7-45c5-911a-c79c3d405ada" x="205" y="22" width="100" height="20"/>
        <textElement/>
        <textFieldExpression><![CDATA[$P{parameter1}.getId()]]></textFieldExpression>
    </textField>
    

    3) Set up the classpath in the iReport: If you are using iReport to design your report you need to tell it where the compiled version of the com.mystuff.User class is located. If you are in eclipse you can just point it to your bin folder in your project, or if you have a jar of the compiled project you can point it to that. The classpath settings are located at Tools -> Options -> Classpath Tab.

    0 讨论(0)
提交回复
热议问题