longbeach751 Posted March 3, 2008 Share Posted March 3, 2008 Hi, I am trying to generate this kind of report : size=150]http://imageblog.blog4ever.com/blogfichiers/182195/photos/260205261821951726.jpeg Both lines are dynamic : we can have more or less than 9 cells in the NOTE linewe can have more or less than 3 cells in the ZONE line I use JavaBeans for my datasource. Here is the Zone object :Code: Here is the Note object :Code: Datasource :Code: Can crosstabs do it ? Thanks for your ideas and feeback. Link to comment Share on other sites More sharing options...
broschb Posted May 22, 2008 Share Posted May 22, 2008 I have run into a similiar problem, I just created a blog post that goes through solving this issue using a JRBeanCollectionDataSource, and specifying the columns at runtime. Check it out and let me know if you have any questions. http://broschb.blogspot.com/2008/05/dynamic-jasper-report-using-crosstabs.html Link to comment Share on other sites More sharing options...
hmorris1970 Posted May 22, 2008 Share Posted May 22, 2008 I had a similar problem and the crosstab was extremly confussing and I could not seem to get it to do exactly what I wanted it to do. First I want professional looking reports with a report header that looks nice and when the detail is added I want things to fit and look nice together something I couldn't seem to figure out how to do with the cross tab. It seemed that even if I could get the cross tab to work for me I was going to have detail that did not always line up with the header, another words the cross tab would grow and shrink but the header would have to be defined for the largest possible cross tab. Example a consolidated Purchase Order that is going to have one or maybe 20 stores, with 20 stores this report is going to need to be much wider then with just the one store. It would look much better if the whole report grows and shrinks based on the number of stores. My solution is to create the whole report definition on the fly using the jasper reports API. This approach to report creation has also helped with a few other reporting problems I have had when managing a lot of reports like inconsistent report headers in the jrxml files, now all my reports inherit a standard report header definition. Time to make a change to the report header when spread through many jrxml files is also no longer an issue since when I want to change something in the header I only change it in one place. Inconsistent ways of displaying certain types of data has been standardized so that all reports inherit this also and only where it is really necessary are they overridden and modified. We also spent a lot of time witting reports for a simple Java bean but have since with the help of reflection been able to examine the been and write a basic report on the fly that follows all the inherited standards and now only have to write code to actually create reports that are not a simple display of the data in the been. Yes there is a learning curve to using the jasper reports API in comparison to ireports but if you are managing a large number of reports or want to do some really complex things it can be well worth it later. Harry Link to comment Share on other sites More sharing options...
hmorris1970 Posted May 22, 2008 Share Posted May 22, 2008 I had a similar problem and the crosstab was extremly confussing and I could not seem to get it to do exactly what I wanted it to do. First I want professional looking reports with a report header that looks nice and when the detail is added I want things to fit and look nice together something I couldn't seem to figure out how to do with the cross tab. It seemed that even if I could get the cross tab to work for me I was going to have detail that did not always line up with the header, another words the cross tab would grow and shrink but the header would have to be defined for the largest possible cross tab. Example a consolidated Purchase Order that is going to have one or maybe 20 stores, with 20 stores this report is going to need to be much wider then with just the one store. It would look much better if the whole report grows and shrinks based on the number of stores. My solution is to create the whole report definition on the fly using the jasper reports API. This approach to report creation has also helped with a few other reporting problems I have had when managing a lot of reports like inconsistent report headers in the jrxml files, now all my reports inherit a standard report header definition. Time to make a change to the report header when spread through many jrxml files is also no longer an issue since when I want to change something in the header I only change it in one place. Inconsistent ways of displaying certain types of data has been standardized so that all reports inherit this also and only where it is really necessary are they overridden and modified. We also spent a lot of time witting reports for a simple Java bean but have since with the help of reflection been able to examine the been and write a basic report on the fly that follows all the inherited standards and now only have to write code to actually create reports that are not a simple display of the data in the been. Yes there is a learning curve to using the jasper reports API in comparison to ireports but if you are managing a large number of reports or want to do some really complex things it can be well worth it later. Harry Link to comment Share on other sites More sharing options...
broschb Posted May 22, 2008 Share Posted May 22, 2008 I would definitely agree with you, learning the JasperReports api is very important. I am familiar with it, but I wouldn't say I know it to depth that you do. The example I gave was a quick and dirty example of a possible way to use crosstabs. It still needs work to make it look better, and to be honest I haven't looked at what would be involved. But it allowed me to create a quick example when I needed it. It all depends on what you need to accomplish. I have not written two jasper reports that are similar yet. This is the first report that I have needed dynamic columns for, and time will tell how this works. But I appreciate your insight into this. This seems like something a lot users encounter, and there does not seem to be straightforward way to accomplish this. :) Link to comment Share on other sites More sharing options...
hmorris1970 Posted May 23, 2008 Share Posted May 23, 2008 The API is large and there is still so much there I do not know, I started with basic stuff and as each report got more complicated was able to learn and integrate more into my understanding of the jasper reports software. Honestly I think most of my coworkers thought my approach initially was more work then it was worth but when it was discovered there was a lack of consistency in the reports being done by the different team members, the effort others put into the simplest changes across so many jrxml files and when they started to run into things they could not accomplish such as the dynamic columns maintaining the consistent look and feel of all our other reports they saw the value. Dynamic Columns seems to be one of the most challenging things in reports with lots of problems and questions on it in the forums and your blog will be very helpful to others who are trying to get an understanding of the cross tab and what it can do for them. Harry Link to comment Share on other sites More sharing options...
broschb Posted July 28, 2008 Share Posted July 28, 2008 Harry, thanks for your insight. I have since moved on to using the jasper reports api. It does make things simplier in the long run as you have mentioned. The one problem that I have and am still trying to figure out, and am hoping you can help with is wrapping columns. If I have a report and the column width exceeds that of the page, have you found a way to wrap these columns to a new page? With crosstabs this was handled automatically. thanks, 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