0

Beginner question about JasperReports

asked 2009-04-06 13:50:30 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-04-07 14:08:43 +0800

***SOLVED***

Hi all,

I'm totally new with JasperReports,

I'm searching how to declare a field for a bean attribute of a bean ?


Example :
If I have a bean Person and this bean have a bean attribute car.

public class Person {

   private Car car;
   ...

}

Private class Car {

  private String dealer;
  ...

}



In myReport.xml,
How to declare/access dealer ? Can I declare it like that ?
<field name="car.dealer" class="java.lang.String">
    <fieldDescription><![CDATA]></fieldDescription>
</field>



And access it like that ?
$F{car.dealer}



Else how can I do it ?


Thanks,

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-04-06 19:29:26 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-04-06 19:34:20 +0800

Have a look at following code:

kunde.java (Bean)

public class Kunde implements java.io.Serializable {

	private static final long serialVersionUID = -7921214349365225047L;

	private long kunId = Long.MIN_VALUE;
	private int version;
	private Filiale filiale;
	private Branche branche;
	private String kunNr = "";
	private String kunMatchcode = "";
	private String kunName1 = "";
	private String kunName2 = "";
	private String kunOrt = "";
	private Boolean kunMahnsperre = false;
	private Set<Auftrag> auftrags = new HashSet<Auftrag>(0);
 ...
  getter/setter

testreport.jrxml

  ...
  <field name="kunName1" class="java.lang.String">
     <fieldDescription><![CDATA]></fieldDescription>
  </field>
  <field name="kunName2" class="java.lang.String">
     <fieldDescription><![CDATA]></fieldDescription>
  </field>
  ...
  here is a property that references to another Bean

  <field name="branche" class="de.daibutsu.backend.model.Branche">
     <fieldDescription><![CDATA]></fieldDescription>
  </field>

  here is a property that references to another Bean

  <field name="filiale" class="de.daibutsu.backend.model.Filiale">
     <fieldDescription><![CDATA]></fieldDescription>
  </field>
  ...

regards
Stephan

link publish delete flag offensive edit

answered 2009-04-06 20:35:47 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-04-06 20:36:01 +0800

Thanks Stephan I will do like in your example.

And for accessing ? Something like that ?

$F{filiale.getSomeProperty()}

link publish delete flag offensive edit

answered 2009-04-07 08:49:46 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Use the iReport for creating the report.
Use the native version.
The NetBeansPlugin have problems to create the xml file correctly.

I have accessed per JRBeanDataSource because i'm going against a hiberntae backend.
There are several datasource templates in the iReport.

Stephan

link publish delete flag offensive edit

answered 2009-04-07 13:23:32 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-04-07 13:35:01 +0800

Thanks Stephan,

The data source of my report is a JRBeanCollectionDataSource.

Yes i'm using iReport, but I had many problems to use hibernate connection in it.
So i'm using a JDBC connection to make the report, then I delete the queryString tag and I change the field declaration name to be like the bean.

But right now i can't make work even with a small report. I mean it's working in iReport before the change, but not in Zk after the change.

I get this error each time when I try to my rapport .jasper with ZK.

...
Caused by: java.lang.NoSuchMethodException: Unknown property '' on class 'class bonDeTravails.BonDeTravailDTO'
	at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1313)
        ...



Any idea ?

Thanks

link publish delete flag offensive edit

answered 2009-04-07 14:08:12 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-04-07 14:09:14 +0800

SOLVED :

On the forum of Jasper they tell me to :

You should either

Remove the empty field descriptions from the JRXML. 
Pass false as isUseFieldDescription when creating the bean data source, e.g. new JRBeanCollectionDataSource(data, false). 


And its working very well now ! :-)

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-06 13:50:30 +0800

Seen: 496 times

Last updated: Apr 07 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More