• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Jasper report - ireport but in java class - dynamic report using jasper report api

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello experts
I am working on jasper reports to generaete reports and also i have downloaded ireports latest version for working with jasper reports and creating reports .. its all working fine ... but now my requirement currently is something different
1. User will have a page where he would input the parameters like From Date - To Date and will select one another parameter
2. Depending on the parameter the search would be executed on the db and all the records matching the same criterial are required to be shown would be saved into the array list or what ever..
3. Now a report shall be generated for the same.. means a pdf, .html will be generated and given to the client in the email ..
so my report creation is dynamic .. i have worked for attaching files in email using java mail and all .. but now the major question is how do i totally create a dynamic report using jasper report and its api..
a sample code matching to the same would be highly appreciated as i am working under time constraints ..
awaiting for response
with regards
vijay
:roll:
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to Other APIs
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say that the report needs to be dynamic, are you saying that you need to dynamically change the structure of the report, or that you need to dynamically change the data in the report? From what you say, the latter sounds like what you are trying to do, and should be very easy to accomplish.
What follows is the guts of my method that runs a JasperReport. You will, of course, need to modify this to suit your preferences.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, you need to either
- pass your data as parameters to the report (if they are just a few simple values),
- pass your report a jdbc connection and specify a query in the report xml, or
- pass your report a JRDataSource
 
vijaykumar shah
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
So i am clearing the perspective of my approach to write this program and asking the question,
What i need is At Run time a report should be created and The report design should also be made at run time and depending on the dynamic results i.e query results the columns and its data should be shown in run time
so it s all together a Complete Dynamic report
So there are few confusions in the code ..
First is what is "aData"
Next is "HashToArraySorter"
Then "NextvaluePair"
Then "Value"
so either provide me with these classes and methods or put the functionality of the same here in the same code..
So for example u can take a Microsoft Access as a database
create a table "personal"
add columns id , name , address , designation , joindate
Now i want to display a report with
Header/title: Personal Data Information
Then below will be the details
ID Name Address Designation JoinDate
1 Vijay Sharjah Software Engineer 12-12-2003
and like wise ..
so in future i would get the records depending on date so let's say i want user from 1-1-2002 till 1-12-2003 so i will get the two parameters from the user and execute the query and show the results..
Now let's say the table in future get's too complex where in the address is not accessible to a user who is making the report ... so when i create a report i would first check what are the user rights and then depending on it i will create the columns and then display the report to the user...
so i guess this would make more clear..
Next thing i wanted to ask is "Do i need to create a .jasper file before executing the program"
Below is the code...along with the error list
You can also modify the code and let me know

--Edited to add CODE tags JAM
[ December 23, 2003: Message edited by: Joel McNary ]
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry - those classes that you have questions about are classes that I wrote. As I said, you will need to modify that code to suit your needs. Basically, aData contains information on how to run a report, HashToArraySorter convertes between an array and a Map, and aValue is a generic Value that will hold any type of data (any primitive or Object). What you should do is use that code as a template for your code, not as the actual code itself.
What Ilja said is accurate: what you want to do is first build the report to report of a database/JRDataSource/whatever (I personally use iReport to do this), compile the report into a .jasper file.
Then in your application you should load that .jasper file and pass it any paramters as needed (use the above code as a template on how to do that).
Finally, print the report.
Judging from what you want to do with allowing different users to see different columns on the report, you have three options. IN terms of least complex to most complex, they are:
1). Create different reports for different users. Use application-level security to control which report which user can run.
2). Create 1 report that takes as a parameter the security level. That report then can have logic that suppresses columns based on that security level.
3). Dynamically build a report. This is not recommended, as it can be quite complex. The simple way to do this is to build the report as XML, compile the report into a .jasper file, run the report, and then (optionally) delete that .jasper file. There may be a more complex way through the Jasper API (I know that this functionality exists in Crystal Reports' C API, although Crystal is not overly Java-friendly), but I do not know of it.
At any rate, this is not really a question relating to a SUN-provided API, so I'm moving this to our Other Open Source Projects forum.
[ December 23, 2003: Message edited by: Joel McNary ]
 
Right! We're on it! Let's get to work tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic