It's not a secret anymore!*
The moose likes Other Open Source Projects and the fly likes user values gets into pdf through iReport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "user values gets into pdf through iReport" Watch "user values gets into pdf through iReport" New topic
Author

user values gets into pdf through iReport

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
My application(swing) has a form. User need to enter the values, and get its printout (or rather pdf).
I am using iReport. SO far, i have worked with getting values from db, using parameters, creating variables.
So, is there such kind of feature with iReport?


kunal
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
What do you have so far, and what is still missing?


Ping & DNS - my free Android networking tools app
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I have thought a solution. Save the data entered by the user to a temp table, and then create pdf via iReport using that table. Next time when another users enters the data, the table is cleared and the process is repeated. IS that a good solution? I doubt it.
I wonder if there is a way to get the data from user via swing form and directly pass it to iReport(or .jasper file)
I am not creating .jrxml file on my own. iReport looks after that
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks for your reply Ulf Dittmer. I have posted the solution which i have thought
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

You don't have to use a database at all. Collect the data off the form and place it in some bean class. Then pass a JRBeanCollectionDataSource instance to your report which is able to pick values from bean properties using $F(fieldName) notation.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks for your reply James Boswell
I collected the data off the form and placed it in a bean class, DataBean.

JRBeanCollectionDataSource constructor takes Collection as parameter, so i should convert the bean data into some kind of collection, like list, and then pass it into JRBeanCollectionDataSource and pass its instance to JasperManager.fillReport method.

In iReport "$F(fieldName) notation" will be $F(bean properties name)

Do correct me if i am wrong.

(I haven't tried it due to some problem in the pc, will try it by the eve)

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Kunal

Everything you have stated seems correct to me (without having specific examples to hand).

I prefer this approach (rather than using SQL within the report template) as it is easier to test - you simply need to pass your collection as opposed to having access to a database and setting up its connection details etc. The bean class can also handle any formatting and derivation logic for the data to be displayed, keeping it out of the report template where it doesn't belong IMO.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
This is what i tried


where dse is the instance of DemandSlipEntity class. In demand Slip.jasper i have used the properties of DemandSlipEntity, such as $F{name}, where name is a property of DemandSlipEntity.

This code gives the following exception :



I have added commons-beanutils to the classpath, but still same problem
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
No reply?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Kunal

How have you added jar to classpath and how are you running the code?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks for your reply James Boswell. Yes, i have added the jar to the classpath. I am running code through console (actually i have created the jar, and then ran it through console , i.e java -jar myapp.jar)
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Kunal

Your problem is that by running the -jar option, values on the classpath are ignored. The JRE options -jar and -cp are mutually exclusive. Here is some info on the -jar option:

-jar
Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests.
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.


I have highlighted the important line in bold.

If you need to run the JAR this way, you will need to edit the Manifest file within it to specify the library (JAR) files it needs to run with. See Adding Classes to the JAR File's Classpath for more information on this.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks James Boswell. That was a really nice explanation. I just came to know from you, that i forgot to mention the name of that external jar in Manifest.txt

I will change the Manifest.txt and let you know the proceedings
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: user values gets into pdf through iReport
 
Similar Threads
Jasper with StoredProcedures
iReport embedded
create pdf file
iReport Question
Is it possible to calculate total within the ireport parameter?