Jump to content
We've recently updated our Privacy Statement, available here ×

askme

Members
  • Posts

    7
  • Joined

  • Last visited

askme's Achievements

Apprentice

Apprentice (3/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. Hi all, I am using a conditional statement to change the font color in jrxml. The condition is if the value is greater than 0 then one color else another color. Please find the statement that i used in the jrxml file in the code section below. The field is of type string <field name="total" class="java.lang.String"/> I get the following error when i try to generate the report net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. The method doubleValue() is undefined for the type String value = (java.lang.String)(((java.lang.String)field_total.getValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$ <---------> 2. The method doubleValue() is undefined for the type String value = (java.lang.String)(((java.lang.String)field_total.getOldValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$ <---------> 3. The method doubleValue() is undefined for the type String value = (java.lang.String)(((java.lang.String)field_total.getValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$ <---------> Thanks Code:<textField > <reportElement x="607" y="0" width="70" height="20"/> <textElement textAlignment="Center"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{total}.doubleValue() >0.0 ? ("<style forecolor='#ff0000'>"+ $F{total}.toString()+"</style>"): ("<style forecolor='#0000ff'>"+ $F{total}.toString()+"</style>")]]></textFieldExpression> </textField>
  2. 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(); } } }
  3. Hi lucianc, Thank you for your kind reply. I am very much new to jasper reports. I was trying to avoid writing a jrxml file which would set my jasper design. That's why i was trying to set my jasper design through the java code. I was able to generate the report when i had less content in it. But now when i have more datas coming in i get the resultant error. These are some of the functionalities which i implemented, i don't know whether this is correct. Please correct me if this is not a right approach. I was setting the page height as a static data like "jasperDesign.setPageHeight(1000);". But i found that the data that i passed was not getting assigned as there was no sufficient page height. So i dynamically set the page height according to the length of data that i have in my HashMap. At times i could find the page height being set as 80,000-90,000. And the error gets popped up. Actually i don't know how to set a page break, like when one page has about 10-15 rows of data in it, then create another page and set the remaining data in it and so on. Lucianc, can you please help me with this. I am also trying to write a .jrxml file which would help me in generating the report the way i want. I am also stuck here, don't know how to move forward. Lucianc, i am starting a new thread for this with the subject 'Creating .jrxml file'. Please have a look into and help me generate my report. Thank you for the help Regards askme
  4. Hi all, I am new to jasper reports. I tried to work around with some sample code and by using a .jrxml file. But i had errors as i progressed. Can somebody help me with generating the jasper report without using .jrxml file. It's like using the jave code . Below mentioned is the code that i tried. If you can see the code below i have set the page height as a static data. Is it possible that i can set the pageheight dynamically according to the data that i have in my hashmap. And probably i may have 500 rows of data which should come under proper column headings like Student Name Class Total Marks Result aaa X 1000 Pass bbb X 870 Pass And all the passed students Result should be shown in green color and the failed students Result should be shown in red color. And if the data exceeds a particular page height the remaining results should be shown in the next page and so on. and finally the report should be exported to .pdf format. How to include all these features with java code rather than using the .jrxml file Any help would be appreciated Thanks Code:JRDesignTextField mJRDesignTextField; JRDesignExpression mJRDesignExpression; JRDesignParameter mJRDesignParameter; JRFont mJRFont;JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("Report"); jasperDesign.setLeftMargin(10); jasperDesign.setRightMargin(10); jasperDesign.setBottomMargin(10); jasperDesign.setTopMargin(10); jasperDesign.setPageHeight(2000); jasperDesign.setPageWidth(800); jasperDesign.setIgnorePagination(false); JRDesignStyle titleText = new JRDesignStyle(); titleText.setName("titleText"); titleText.setDefault(false); titleText.setMode(JRElement.MODE_OPAQUE); titleText.setFontName("Arial"); titleText.setBackcolor(new Color(10025880)); titleText.setFontSize(16); titleText.setLineSpacing(new Byte((byte) 10)); titleText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); try { jasperDesign.addStyle(titleText); } catch (JRException e) { e.printStackTrace(); }JRDesignStyle headingText = new JRDesignStyle(); headingText.setName("headingText"); headingText.setMode(JRElement.MODE_OPAQUE); headingText.setFontName("Arial"); headingText.setForecolor(new Color(16777215)); headingText.setBackcolor(new Color(6776679)); headingText.setFontSize(10); try { jasperDesign.addStyle(headingText); } catch (JRException e) { e.printStackTrace(); }JRDesignBand band = new JRDesignBand(); band.setHeight(30); JRDesignStaticText statictextField = new JRDesignStaticText(); statictextField.setText("Student Report"); statictextField.setX(0); statictextField.setY(0); statictextField.setWidth(775); statictextField.setHeight(26); statictextField.setStyle(titleText); JRDesignLine line = new JRDesignLine(); line.setX(0); line.setY(26); //line.setWidth(515); line.setHeight(0); band.addElement(statictextField); band.addElement(line); jasperDesign.setTitle(band);
  5. Hi all, I am using an api to generate the jasper report. I am trying to export the data in the HashMap through jasper report to a .pdf file. I am getting the following error. -------------------------------- net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. Too many constants, the constant pool for Product_Report_1262846848578_594569 would exceed 65536 entries public class Product_Report_1262846848578_594569 extends JREvaluator <---------------------------------> 1 errors at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:195) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:219) ---------------------------------- My code worked fine when i generated the report with less content in it (or) less values in the hashmap. Now i have more values in my hashmap and i am not able to generate the report and the .pdf file. Please help me Thanks
  6. Hi all, I am new to jasper report. Please find the below code with which i am generating a report in.pdf format. The report is working fine. It's a student report. Now the problem is i want to set the color for the text in the marks column against a student according to the mark he get. Let's say for example.. the minimum mark that a student should earn is 40 out of 100. If a student mark is less that 40 then the marks text should be in red color and if the mark is greater than 40 then the marks text should be in green color. How can i include this condition in the code given below. I could find some examples where they set the condition in the .jrxml file. But i could not find any similiar according to the below code. Kindly help me. It's urgent. Thanks Code:import net.sf.jasperreports.engine.JRAlignment;import net.sf.jasperreports.engine.JRConditionalStyle;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.JREmptyDataSource;import net.sf.jasperreports.engine.JRException;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.data.JRBeanCollectionDataSource;import net.sf.jasperreports.engine.design.JRDesignBand;import net.sf.jasperreports.engine.design.JRDesignConditionalStyle;import net.sf.jasperreports.engine.design.JRDesignExpression;import net.sf.jasperreports.engine.design.JRDesignField;import net.sf.jasperreports.engine.design.JRDesignLine;import net.sf.jasperreports.engine.design.JRDesignStaticText;import net.sf.jasperreports.engine.design.JRDesignStyle;import net.sf.jasperreports.engine.design.JRDesignTextField;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.engine.xml.JRConditionalStyleFactory;import net.sf.jasperreports.engine.xml.JRConditionalStyleFillerFactory;import net.sf.jasperreports.view.JasperViewer;import net.sf.jasperreports.view.save.JRCsvSaveContributor;import java.awt.Color;import java.io.File;import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class sample1 { public static void main(String[] args) { try { List dataList = new ArrayList(); HashMap dataMap = new HashMap(); dataMap.put("studid", "1"); dataMap.put("classid", "11"); dataMap.put("teacherid", "ABC"); dataMap.put("name", "Mathew"); dataMap.put("subjectid", "5"); dataMap.put("marks", "25"); dataMap.put("total", "100"); dataList.add(dataMap); dataMap = new HashMap(); dataMap.put("studid", "2"); dataMap.put("classid", "11"); dataMap.put("teacherid", "ABC"); dataMap.put("name", "Christy"); dataMap.put("subjectid", "5"); dataMap.put("marks", "65"); dataMap.put("total", "100"); dataList.add(dataMap); dataMap = new HashMap(); dataMap.put("studid", "3"); dataMap.put("classid", "11"); dataMap.put("teacherid", "ABC"); dataMap.put("name", "George"); dataMap.put("subjectid", "5"); dataMap.put("marks", "65"); dataMap.put("total", "100"); dataList.add(dataMap); JasperDesign jasperDesign = getProductJasperDesign(); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(dataList); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), jrBeanCollectionDataSource); JasperViewer.viewReport(jasperPrint); JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/JasperReport/Sample.pdf"); } catch (Exception e) { e.printStackTrace(); } } private static JasperDesign getProductJasperDesign() throws JRException { JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("Product_Report"); jasperDesign.setLeftMargin(10); jasperDesign.setRightMargin(10); jasperDesign.setBottomMargin(20); jasperDesign.setTopMargin(20); jasperDesign.setPageHeight(600); jasperDesign.setPageWidth(800); jasperDesign.setColumnWidth(500); jasperDesign.setIgnorePagination(true); // Add styles to report JRDesignStyle titleText = new JRDesignStyle(); titleText.setName("titleText"); titleText.setDefault(false); titleText.setMode(JRElement.MODE_OPAQUE); titleText.setFontName("Verdana"); titleText.setBackcolor(new Color(10025880)); titleText.setFontSize(16); //titleText.setUnderline(true); titleText.setLineSpacing(new Byte((byte) 10)); titleText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); jasperDesign.addStyle(titleText); JRDesignStyle headingText = new JRDesignStyle(); headingText.setName("headingText"); headingText.setMode(JRElement.MODE_OPAQUE); headingText.setFontName("Arial"); headingText.setForecolor(new Color(16777215)); headingText.setBackcolor(new Color(6776679)); headingText.setFontSize(10); jasperDesign.addStyle(headingText); JRDesignStyle reportingText = new JRDesignStyle(); reportingText.setName("reportingText"); reportingText.setDefault(false); reportingText.setMode(JRElement.MODE_OPAQUE); reportingText.setFontName("Arial"); reportingText.setBackcolor(new Color(16119285)); reportingText.setFontSize(9); jasperDesign.addStyle(reportingText); // End of styles // Field Values JRDesignField field = new JRDesignField(); field = new JRDesignField(); field.setName("studid"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("classid"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("teacherid"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("name"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("subjectid"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("marks"); field.setValueClass(String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("total"); field.setValueClass(String.class); jasperDesign.addField(field); JRDesignBand band = new JRDesignBand(); band.setHeight(40); JRDesignStaticText statictextField = new JRDesignStaticText(); statictextField.setText("Student Report"); statictextField.setX(0); statictextField.setY(0); statictextField.setWidth(700); statictextField.setHeight(26); statictextField.setStyle(titleText); JRDesignLine line = new JRDesignLine(); line.setX(0); line.setY(26); //line.setWidth(515); line.setHeight(0); band.addElement(statictextField); band.addElement(line); jasperDesign.setTitle(band); // Page header band = new JRDesignBand(); band.setHeight(20); statictextField = new JRDesignStaticText(); statictextField.setX(0); statictextField.setY(0); statictextField.setWidth(70); statictextField.setHeight(20); statictextField.setText("Student Id"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(72); statictextField.setY(0); statictextField.setWidth(70); statictextField.setHeight(20); statictextField.setText("Class ID"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(146); statictextField.setY(0); statictextField.setWidth(70); statictextField.setHeight(20); statictextField.setText("Teacher Id"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(220); statictextField.setY(0); statictextField.setWidth(180); statictextField.setHeight(20); statictextField.setText("Name"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(404); statictextField.setY(0); statictextField.setWidth(50); statictextField.setHeight(20); statictextField.setText("Subject Id"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(458); statictextField.setY(0); statictextField.setWidth(50); statictextField.setHeight(20); statictextField.setText("Marks"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); statictextField = new JRDesignStaticText(); statictextField.setX(512); statictextField.setY(0); statictextField.setWidth(50); statictextField.setHeight(20); statictextField.setText("Total"); statictextField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); statictextField.setStyle(headingText); band.addElement(statictextField); jasperDesign.setPageHeader(band); // Add Detail Section band = new JRDesignBand(); band.setHeight(19); JRDesignTextField textField = new JRDesignTextField(); textField.setX(0); textField.setY(0); textField.setWidth(70); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); JRDesignExpression expression = new JRDesignExpression(); expression = new JRDesignExpression(); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{studid}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(72); textField.setY(0); textField.setWidth(70); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{classid}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(146); textField.setY(0); textField.setWidth(70); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{teacherid}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(220); textField.setY(0); textField.setWidth(180); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{name}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(404); textField.setY(0); textField.setWidth(50); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{subjectid}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(458); textField.setY(0); textField.setWidth(50); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{marks}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setX(512); textField.setY(0); textField.setWidth(50); textField.setHeight(18); textField.setStretchWithOverflow(true); textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); textField.setStyle(reportingText); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("$F{total}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); jasperDesign.setDetail(band); //Column footer band = new JRDesignBand(); jasperDesign.setColumnFooter(band); //Page footer band = new JRDesignBand(); jasperDesign.setPageFooter(band); //Summary band = new JRDesignBand(); jasperDesign.setSummary(band); return jasperDesign; }}
  7. Hi all, I am new to jasper reports. Actually i need to show some data in jasper report and then export it to either .xls (or) .csv format. Please find the attachment, actually that is the format in which my report need to be generated. At first i thought of doing the template in .jrxml format. But some of the marks for the students should be displayed in red color, if it the students mark is less that average mark. So i thought of doing the template coding in java and then pass on the student values to this class file. Please find the sample codes which i was trying to use for generating a sample report in the code segment below. As a beginner i don't know hot to do this. Can somebody help me generate a report in the format as shown in the file(please find the attachment) using a similiar type of coding as mentioned in the code section and with out using .jrxml template file. Kindly help me. Thanks Code://Actually this if the type of coding i wish to follow.Something likeimport net.sf.jasperreports.engine.JRAlignment;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;import net.sf.jasperreports.engine.design.JRDesignBand;import net.sf.jasperreports.engine.design.JRDesignExpression;import net.sf.jasperreports.engine.design.JRDesignField;import net.sf.jasperreports.engine.design.JRDesignLine;import net.sf.jasperreports.engine.design.JRDesignStaticText;import net.sf.jasperreports.engine.design.JRDesignStyle;import net.sf.jasperreports.engine.design.JRDesignTextField;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.view.JasperViewer;//---Then write a function which sets the design---private static JasperDesign getProductJasperDesign() throws JRException { JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("Product_Report"); jasperDesign.setLeftMargin(10); jasperDesign.setRightMargin(10); jasperDesign.setBottomMargin(20); jasperDesign.setTopMargin(20); jasperDesign.setPageHeight(800); jasperDesign.setPageWidth(600); jasperDesign.setColumnWidth(500); jasperDesign.setIgnorePagination(true); // Add styles to report JRDesignStyle titleText = new JRDesignStyle(); titleText.setName("titleText"); titleText.setDefault(false); titleText.setMode(JRElement.MODE_OPAQUE); titleText.setFontName("Arial"); titleText.setFontSize(16); jasperDesign.addStyle(titleText);}//And then finally call this design to the main function like JasperDesign jasperDesign = getProductJasperDesign(); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);//and then export the result to either .xls (or) .csv format.
×
×
  • Create New...