Jump to content

Creating .jrxml file


askme

Recommended Posts

Hi all,

             I am trying to create a JRXML file for my report. My report format is like this

                                                            STUDENT REPORT

Roll No        Student Name                         Class                            Marks                 Result

  01                aaa                                             X                                   1000                     Pass

  02                 bbb                                            X                                    880                       Pass

  03                 ccc                                             X                                    470                        Fail

  04                 ddd                                            X                                    500                       Pass

  05                 eee                                             X                                   450                       Fail

  06                 fff                                                 X                                   800                       Pass

 

Please find the jrxml file that i am using attached along with this thread.

Please find the java code also.

 

Now the problem that i have is, i am able to get the title and the columheading in my report, but the parameter values that i passed are not getting displayed in my report.

 

And some more doubts that i have is, how should i pass the values if i have around 1000 student details. Can we do it like,

i have the results in a two dimensional array

for(int i=0;i<studArray.length;i++)

{

             parameters.put("rollno", studArray[0]);

             parameters.put("name", studArray[1]);
             parameters.put("class", studArray[2]);
             parameters.put("marks", studArray[3]);
             parameters.put("result", studArray[4]);    

}

But the doubt that i have here is , as the parameter name is unique, i think the last value in the array will only get assigned. Don't know exactly.

 

And another doubt that i have is i need to set a condition for the 'Result' column. If the students marks is greater than 500 then the Result is 'Pass' and the font color for the result is Green. If the marks is less than 500 then the Result is 'Fail' and the font color is Red. Is it possible to set this condition in the jrxml file.

 

And one more thing that i need is the page break. When my details section of a page exceeds certain no of rows of data, then a new page should be created an the remaining data should be printed on that page and so on..

 

 

I am really stuck with this, the parameters are not getting passed and don't know how to attain the remaining features as well , as mentioned above.

 

Any help would be appreciated.

Thanks

 

 

Code:
import java.util.HashMap;	import java.util.Map;	 	import net.sf.jasperreports.engine.JasperCompileManager;	import net.sf.jasperreports.engine.JasperExportManager;	import net.sf.jasperreports.engine.JasperFillManager;	import net.sf.jasperreports.engine.JasperPrint;	import net.sf.jasperreports.engine.JasperReport;	import net.sf.jasperreports.engine.design.JasperDesign;	import net.sf.jasperreports.engine.xml.JRXmlLoader;	import net.sf.jasperreports.view.JasperViewer;		public class StudentReport {				public static void main(String[] args) {				 try {				 String filePath = "D:/report/studentreport.jrxml";				 JasperDesign jasperDesign = JRXmlLoader.load(filePath);				 				 JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);				 				 Map parameters = new HashMap();				 parameters.put("rollno", "01");				 parameters.put("name", "aaa");				 parameters.put("class", "X");				 parameters.put("marks", "1000");				              parameters.put("result","Pass");				 				 				 JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);				 				 JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/jasperreport/SReport.pdf");				 				 JasperViewer.viewReport(jasperPrint);				 } catch (Exception e) {				 e.printStackTrace();				 }				 }			}
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I think your problem is: the detail band is not displayed at all. It's not that the parameters are not passed.

Your report has no query, also you don't seem to be passing any database connection (not sure how that works).

Since there is no query, no records are returned and the detail band is not displayed.

Try running it with an empty data source.  Or just move the fields displaying the parameters into the title band.

 

What you are trying to do is pass the data directly to the report, instead of passing a database connection from which it can retrieve its own data (which is the common approach).

For this you need a custom datasource.

Check out this link. http://www.jasperassistant.com/docs/guide/ch03s02.html

Scroll down at the end for an example of a JRBeanCollectionDataSource datasource. So what you need is populate the collection with Student beans.

In order to properly display this data in the report you need to have fields with the name of the properties and in the detail band display those fields, not parameters.

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...