nibedita Posted April 12, 2012 Share Posted April 12, 2012 Hi All,I am using a JRBeanCollectionDataSource to generate report.I have 2 layer of subreports.I send a datasource of type JRBeanCollectionDataSource .In report i required 4 fields i.e(qty,rate,poref,date)For poref and date i required one object of userdefined class(i.e PurchaseOrderItem).But the data source contains super class of PurchaseOrderItem i.e OrderItem.Sometimes it shows the blank report but sometimes it show NULLPOINTEREXCEPTION.even if When i am declaring filed <field name="purchaseOrderItem" class="com.realty.model.PurchaseOrderItem"/>it gives same Exception.But when i am declaring <field name="orderItem" class="com.realty.model.OrderItem"/> it does not give any exception.but how i retrieve poref and date from OrderItem(It is declare in its subClass PurchaseOrderItem)Can anyone help me please Its urgent. ThanksNibedita 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="MatrialConsumptionStatement_InventoryItem_subreport1" language="groovy" pageWidth="676" pageHeight="802" columnWidth="676" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <parameter name="REPORT_JRXML_DIR" class="java.lang.String"/> <parameter name="totalGroupWiseEstimationValue" class="java.lang.Double"/> <parameter name="groupDescription" class="java.lang.String"/> <field name="qty" class="java.lang.Double"/> <field name="rate" class="java.lang.Double"/> <field name="purchaseOrderItem" class="com.realty.model.PurchaseOrderItem"/> <background> <band splitType="Stretch"/> </background> <columnHeader> <band height="72" splitType="Stretch"> <rectangle> <reportElement x="0" y="47" width="675" height="20" backcolor="#FFCCCC"/> </rectangle> <staticText> <reportElement x="69" y="47" width="41" height="20" forecolor="#6666FF" backcolor="#FFFFFF"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Qty]]></text> </staticText> <staticText> <reportElement x="137" y="47" width="35" height="20" forecolor="#6666FF" backcolor="#FFFFFF"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Rate]]></text> </staticText> <staticText> <reportElement x="248" y="47" width="51" height="20" forecolor="#6666FF" backcolor="#FFFFFF"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Value]]></text> </staticText> <staticText> <reportElement x="377" y="47" width="57" height="20" forecolor="#6666FF" backcolor="#FFFFFF"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Po.Ref]]></text> </staticText> <staticText> <reportElement x="507" y="47" width="48" height="20" forecolor="#6666FF" backcolor="#FFFFFF"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Date]]></text> </staticText> <staticText> <reportElement x="0" y="30" width="100" height="17" forecolor="#993300"/> <textElement> <font fontName="Arial" size="12" isBold="true"/> </textElement> <text><![CDATA[Estimate]]></text> </staticText> </band> </columnHeader> <detail> <band height="25" splitType="Stretch"> <textField isStretchWithOverflow="true" pattern="##,##,###,##0.00;(##,##,###,##0.00)"> <reportElement x="23" y="0" width="63" height="20"/> <textElement textAlignment="Right"/> <textFieldExpression class="java.lang.Double"><![CDATA[$F{qty}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" pattern="##,##,###,##0.00;(##,##,###,##0.00)"> <reportElement x="98" y="0" width="74" height="20"/> <textElement textAlignment="Right"> <font fontName="Arial"/> </textElement> <textFieldExpression class="java.lang.Double"><![CDATA[$F{rate}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement x="353" y="0" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$F{purchaseOrderItem}.getPurchaseOrder().getReferenceNo()]]></textFieldExpression> </textField> <textField pattern="dd-MM-yyyy" isBlankWhenNull="true"> <reportElement x="477" y="0" width="95" height="20"/> <textElement textAlignment="Center"> <font fontName="Arial"/> </textElement> <textFieldExpression class="java.util.Date"><![CDATA[$F{purchaseOrderItem}.getPurchaseOrder().getOrderDate()]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" pattern="##,##,###,##0.00;(##,##,###,##0.00)"> <reportElement x="210" y="0" width="74" height="20"/> <textElement textAlignment="Right"> <font fontName="Arial"/> </textElement> <textFieldExpression class="java.lang.Double"><![CDATA[$F{rate}*$F{qty}]]></textFieldExpression> </textField> </band> </detail> <summary> <band height="26"> <textField pattern="##,##,###,##0.00;(##,##,###,##0.00)"> <reportElement x="98" y="6" width="202" height="20"/> <textElement/> <textFieldExpression class="java.lang.Double"><![CDATA[$P{totalGroupWiseEstimationValue}]]></textFieldExpression> </textField> <staticText> <reportElement x="23" y="6" width="75" height="20"/> <textElement> <font fontName="Arial"/> </textElement> <text><![CDATA[Total estimate]]></text> </staticText> </band> </summary></jasperReport> Link to comment Share on other sites More sharing options...
sanbez Posted April 13, 2012 Share Posted April 13, 2012 In expression $F{purchaseOrderItem}.getPurchaseOrder().getOrderDate() is $F{purchaseOrderItem}.getPurchaseOrder() always not null? Are you check code of method getJRFieldValue for subreport for null this value? It's so hard to give advice without code and stacktrace. In what place NULLPOINTEREXCEPTION occurs? Link to comment Share on other sites More sharing options...
nibedita Posted April 13, 2012 Author Share Posted April 13, 2012 Thanks for reply.PurchaseOrderItem extends OrderItem.That OrderItem field is in my subrepoprt datasource.But i declare its subcalss i.e PurchaseOrderItem as field in subreport.When i am declaring <field name="purchaseOrderItem" class="com.realty.model.PurchaseOrderItem"/>net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : purchaseOrderItem at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:710) at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:329) at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:419) at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:378) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2028) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:757) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:269) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:127) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:942) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:860) at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:612) at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59) at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205) at java.lang.Thread.run(Thread.java:619)Caused by: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : purchaseOrderItem at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123) at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96) at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100) at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:823) at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:787) at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1478) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:125) ... 6 moreCaused by: java.lang.NoSuchMethodException: Unknown property 'purchaseOrderItem' at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1122) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290) at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111) ... 12 moreRegardsNibedita Link to comment Share on other sites More sharing options...
sanbez Posted April 13, 2012 Share Posted April 13, 2012 This is another error. It's not NullPointerException.This message is signed that your bean havn't method getPurchaseOrderItem() in bean. You may define only fields with existing getters.If you define field "purshaseOrderItem" in jrxml, you must write get-method with correspondent name.I am don't understand how you pass collection in subreport?Is it new JRBeanCollectionDataSource(Collection<PurchaseOrderItem>) in subreport expression?Or is it pass to $P_DATA_SOURCE?Post Edited by sanbez at 04/13/2012 08:42 Link to comment Share on other sites More sharing options...
nibedita Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks Sanbez JRBeanCollectionDataSource(Collection<EstimateItem>) this is the bean. EstimateItem class contains OrderItem(which is a super class of PurchaseOrderItem). That bean class contains the setter getter method of OrderItem not the PurchaseOrderItem. OrderItem is a hibernate model class and its joined-subclass is PurchaseOrderItem. RegardsNibedita Link to comment Share on other sites More sharing options...
sanbez Posted April 17, 2012 Share Posted April 17, 2012 Sorry, I am don't work with hibernate. Probably I can't help.But if you can write "clever" method getDate() for EstimateItem then you can define field date in report.But I am don't know how to do this whith "poref" :( Good luck Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now