i have .jrxml file , pass params code it. have orde
r class has fields double price
, int quantity
, product product
. situation simple, when need pass price or quantity, this:
<textfieldexpression class = "java.lang.integer"> <![cdata[$f{quantity}]]> </textfieldexpression>
the problem appears when try pass product.getname()
. tried like:
<textfieldexpression class = "java.lang.string"> <![cdata[$f{product}.getname()]]> </textfieldexpression>
and many others keep getting error: net.sf.jasperreports.engine.design.jrvalidationexception: report design not valid : 1. field not found : product
do have idea how solve problem?
for example have pair of javabeans (pojo):
public class order { private double price; private int quantity; private product product; // public getters } public class product { private string name; // public getters }
and declare report's datasource in manner this: (yes, guava)
jrbeancollectiondatasource datasource = new jrbeancollectiondatasource(lists.newarraylist(immutablelist.<order>builder() .add(new order(1000.2, 10, new product("phone"))) .add(new order(10200.0, 2, new product("tv"))) .build()));
in case using fields declaration:
<field name="order" class="java.lang.object"> <fielddescription><![cdata[_this]]></fielddescription> </field> <field name="price" class="java.lang.double"/> <field name="quantity" class="java.lang.integer"/> <field name="productname" class="java.lang.string"> <fielddescription><![cdata[product.name]]></fielddescription> </field>
you can use such expressions:
<textfield> <reportelement x="0" y="0" width="100" height="30"/> <textfieldexpression><![cdata[$f{price}]]></textfieldexpression> </textfield> <textfield> <reportelement x="100" y="0" width="100" height="30"/> <textfieldexpression><![cdata[$f{quantity}]]></textfieldexpression> </textfield> <textfield> <reportelement x="200" y="0" width="100" height="30"/> <textfieldexpression><![cdata[$f{productname}]]></textfieldexpression> </textfield>
note:
- don't forget getters should public
- more info: javabean data sources
- the explanation of _this using samples can found in posts:
Comments
Post a Comment