mondal.brata Posted February 21, 2019 Share Posted February 21, 2019 i Guys,I am beginner with Jasper report, and I got this below situation. I know this topic habe been discussed here but seriously speaking I went through many topic, tried, but no luck, some how I am not able to make it. Please help me...Situation: I need to pass a `List<List<?>>` from my java layer to Jasper to make a PDF. Some post I saw people suggested to use SubReport and in Some post people suggested to use List component in JasperReport. I tried both and finally messed up. Please suggest which one to use to make my work done, and it will be very grateful if any one can pass the source code or complete clear Idea how to implement this. I need this to print like below: 1.Patient Name: abcd Test Name: GlucoseTest Result: 24 Ref.Range: 10-30 mg/dl Test Name: TSH Result: 0.5 Ref.Range: 0.1-0.9 mg/dl 2.Parient Name: efgh Test Name: GlucoseTest Result: 24 Ref.Range: 10-30 mg/dl Test Name: TSH Result: 0.5 Ref.Range: 0.1-0.9 mg/dl Test Name: GlucoseTest Result: 24 Ref.Range: 10-30 mg/dl Test Name: TSH Result: 0.5 Ref.Range: 0.1-0.9 mg/dl 3.Parient Name: efgh Test Name: GlucoseTest Result: 24 Ref.Range: 10-30 mg/dl . . .and so on...Please help, i am puzzled, thank in advance. Link to comment Share on other sites More sharing options...
C-Box Posted February 27, 2019 Share Posted February 27, 2019 Hi,just use the Tests as a List within the Patient class e.g. (just pseudocode):public class Patient {private String name;private List<Test> tests = new ArrayList<Test>();... (constructor and filling methods)// returns the name of the patientpublic String getName(){ return this.name;} //Creates a new DataSource for all tests for this patient so that you can define a Field "TestsDS" of type JRBeanCollectionDataSource in JRXML that can directly used for SubReport DataSourceExpression public JRBeanCollectionDataSource getTestsDS(){ return new JRBeanCollectionDataSource(this.tests); }}[/code]For the patients itself you can also create a List<Patient> allPatients in your code and also use this JRBeanCollectionDataSource(allPatients) for MainDataSource at filling the report.Don't use ListElements you will get in trouble with unwanted pagebreaks, formatting and calculation issues. So after 15 years using JasperReports I'd advice using SubReports therefore - you will be much more flexible in future - even if you don't calculate anything at the moment! :-)hth + regardsC-Box 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