pnvswamy Posted October 20, 2008 Share Posted October 20, 2008 Hi to all, I dont know how to use sub reports in the main report.i want help from u who are having knowledge on sub reports.And i want how to pass parameter from main report data to the sub report.Please help me . Link to comment Share on other sites More sharing options...
shrije Posted October 20, 2008 Share Posted October 20, 2008 subreports are used where you want to represent data that is child to the data in the parent report. You could show data that is a reference data which may not any relation. You can have as many levels of subreports. You can pass parameters to the subreport jrxml from the subreport parameter tab in the subreport element. The same parameter name is to be specified in the subreport jrxml in order that the value is passed sucessfully. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 I understood the usage of subreports.I developed the main report and sub report using IREPORT tool.In i report i am directly connecting the database.So both reports are working fine.My problem came when i am using the application.In the application i am using JRBeanCollectionDatasource for the Report data as a ArrayList of BeanClasses.Could you please help me how to pass parameter to sub report from the main report in the application. Link to comment Share on other sites More sharing options...
shrije Posted October 21, 2008 Share Posted October 21, 2008 You can pass parameters to the subreport jrxml from the subreport parameter tab in the subreport element. The same parameter name is to be specified in the subreport jrxml in order that the value is passed sucessfully. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 hiI am generating jasper reports with out writing any query string in .jrxml files.I am using JRBeanCollectionDataSource.I am facing problems in sub reports.main report having the fields like empCode,Name only.These fields are getting throguh EmpBeans as an arrylist to passing a parameter to JRBeanCollectionDataSource.Based on empcode i am getting the employee projects done have to shown using sub reports.These projects are under another ProjectBean.How can i fill the sub report based on the empCode.Please help me.If i use query strings in jrxml there is no problem in ireport. Link to comment Share on other sites More sharing options...
shrije Posted October 21, 2008 Share Posted October 21, 2008 Class MainReport{List<EmpDetail>List <ProjectDetail>}Class EmpDetail{empCode,Name}Class ProjectDetail{empCode, projectDetails}Your main class should look like this.You have beancollection of MainReport only.The mainReport will have two fields automatically created as List. Once you done that change the subreport datasource as JavaBeancollectionSource(NameofListField). This way you can achieve very complex reports. Your subreport just needs to have the fields from the respective beans. It is difficult to write all in message but i have written enough for your understanding. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 In this employeeList is the arryList i am fiiling the main report.In that it is having EmpDetail bean class.For each it has empCode ,for ecah code i want Project details to fill as arrayList.In Main report i am passing parameter as $P{empCode}where i have to check the condition and where i ahave to fill the sub report as arryList based on EmpCode. Thank you,My problem is for the main report i am using EmpDetail bean classand for sub report i am using ProjectDetails bean class.first i am filling the main report like this :---------------------------------------------------------------------new File(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"));null; new java.util.HashMap();//parameters.put("subReport",jasperReport1);JRBeanCollectionDataSource ds =JRBeanCollectionDataSource(employeeList);JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds );new-----------------------------------------File fileSrc =File destFile =JasperDesign jasperDesign = JRXmlLoader.load(fileSrc);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); java.util.Map parameters = Link to comment Share on other sites More sharing options...
shrije Posted October 21, 2008 Share Posted October 21, 2008 You might have to change the implementation slightly.You dont have to populate sub report as arryList based on EmpCode. All the data will be populated right before you generate the report. So you have to organise your data in the following form.Class EmpDetail {String EmpCodeList ProjectDetailsClass}So your first main report JRBeanCollectionDataSource is JrBeanCollectionDataSource(List<EmpDetail>)Rest of the population is just iReport Configuration of subreport. You subreport should have fields for ProjectDetailsClass.Change the subreport element properties to following:-At the subreport tab select "use DataSource Expression"Here enter "new JrBeanCollectionDataSource(List<ProjectDetail>)" as the datasource expression.I hope i am clear now. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 I am filling the main report like this:----------------------------------------File fileSrc = new File(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"));File destFile = null; JasperDesign jasperDesign = JRXmlLoader.load(fileSrc);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); java.util.Map parameters = new java.util.HashMap(); /*employeeList is the EmpDetail List*/JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(employeeList);JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds );------------------------------------------------------------------------------i want to fill sub report alsoPlease help me...... Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 I am filling the main report like this:----------------------------------------File fileSrc = new File(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"));File destFile = null; JasperDesign jasperDesign = JRXmlLoader.load(fileSrc);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); java.util.Map parameters = new java.util.HashMap(); /*employeeList is the EmpDetail List*/JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(employeeList);JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds );------------------------------------------------------------------------------i want to fill sub report alsoPlease help me...... Please see the files:MainReport : PaEmployeeDetailReport.jrxmlsub report : Employee_subreport1.jrxmlMethod in java class is :generateReport() Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 generateMethod looks like this:new PaReportsHelper();"reports/Employee_subreport1.jrxml");"reports/Employee_subreport1.jasper");out.println("List Size:"+employeeList.size());if(employeeList.size() == 0 ){new ActionMessage("PA.PaEmpReportsByStatusAction.generateReport.noData");"noData", noData);return mapping.findForward("noRecords");try{// JasperCompileManager.compileReportToFile(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"), getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jasper"));JasperDesign jasperDesign1 = JRXmlLoader.load(subFileSrc);JasperReport jasperReport1 = JasperCompileManager.compileReport(jasperDesign1);JasperCompileManager.compileReportToFile(subFileSrc,subFileDest );List projects = reportsHelper.employeeProjectDetails( File fileSrc =File destFile =JasperDesign jasperDesign = JRXmlLoader.load(fileSrc);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); java.util.Map parameters = parameters.put(parameters.put(JRBeanCollectionDataSource ds =JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds );JRExporter jrExporter =new Integer(5));new File(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"));null; new java.util.HashMap();"subReport",jasperReport1);"subds",new JRBeanCollectionDataSource(projects));new JRBeanCollectionDataSource(employeeList);null; PaReportsHelper reportsHelper =String subFileSrc =getServlet().getServletContext().getRealPath(String subFileDest =getServlet().getServletContext().getRealPath(List employeeList = reportsHelper.getEmployeeDetails123(department,employee,status,type,loginUnitId,subFileSrc,subFileDest);System. ActionMessage noData =messages.add(saveMessages(request, messages); } Link to comment Share on other sites More sharing options...
pnvswamy Posted October 21, 2008 Author Share Posted October 21, 2008 the generateReport() method looks like this{PaReportsHelper reportsHelper =new PaReportsHelper();"reports/Employee_subreport1.jrxml");"reports/Employee_subreport1.jasper");out.println("List Size:"+employeeList.size());if(employeeList.size() == 0 ){new ActionMessage("PA.PaEmpReportsByStatusAction.generateReport.noData");"noData", noData);return mapping.findForward("noRecords");try{// JasperCompileManager.compileReportToFile(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"), getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jasper"));JasperDesign jasperDesign1 = JRXmlLoader.load(subFileSrc);JasperReport jasperReport1 = JasperCompileManager.compileReport(jasperDesign1);JasperCompileManager.compileReportToFile(subFileSrc,subFileDest );List projects = reportsHelper.employeeProjectDetails( File fileSrc =File destFile =JasperDesign jasperDesign = JRXmlLoader.load(fileSrc);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); java.util.Map parameters = parameters.put(parameters.put(JRBeanCollectionDataSource ds =JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds );new Integer(5));new File(getServlet().getServletContext().getRealPath("reports/PaEmployeeDetailReport.jrxml"));null; new java.util.HashMap();"subReport",jasperReport1);"subds",new JRBeanCollectionDataSource(projects));new JRBeanCollectionDataSource(employeeList);}String subFileSrc =getServlet().getServletContext().getRealPath(String subFileDest =getServlet().getServletContext().getRealPath(List employeeList = reportsHelper.getEmployeeDetails123(department,employee,status,type,loginUnitId,subFileSrc,subFileDest);System. ActionMessage noData =messages.add(saveMessages(request, messages); } Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 hi,I am having the field type ArrayList in employee Bean.I want to show that list in Report.Ex : i am setting the projectDetails as a ArrayList in Bean.And i configured the <field name="projectDetails" class="java.util.ArrayList"/>then i am getting the exception like --->Could you please help me how to represent arraylist type Data in .jrxml file.Error retrieving field value from bean : projectDetails Link to comment Share on other sites More sharing options...
shrije Posted October 22, 2008 Share Posted October 22, 2008 Put it as java.util.List. Also change the subreport properties as i described earlier. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 i am not using any sub report.Only single report .And i want the ArrayList data to be printed in the report.i just put the filed like <filed name="projectDeatils" class="java.util.ArrayList"/>i dont know how to print the ArrayList data. Link to comment Share on other sites More sharing options...
shrije Posted October 22, 2008 Share Posted October 22, 2008 You need to use subreport for this to work. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 First of all Thanks for ur reply.ok i am using sub report.If i given the <field name="projectDetails" class="java.util.ArrayList"/>then it is giving the Error retrieving field value from bean : projectDetails Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 Hi,i given like this in .jrxml file< field name="projDetails" class="java.util.List"/>and in sub report part<subreport> <reportElement x="9" y="665" width="502" height="20"/> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{projDetails})]]></dataSourceExpression> <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{subReport}]]></subreportExpression> </subreport>then it was giving the error likeErrors were encountered when compiling report expressions class file:1. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getValue())));/*$JR_EXPR_ID=39$*/<------------------------>2. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getOldValue())));/*$JR_EXPR_ID=39$*/<------------------------>3. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getValue())));/*$JR_EXPR_ID=39$*/<------------------------>3 errors Please help me Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 Thank you for your help,and spending time for my problems.Now i got the report.Keep in touch.Very very Thanks to you. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 22, 2008 Author Share Posted October 22, 2008 one doubt i am having,Please rectify me.What my doubt is In the main report , i am giving the width and height for the sub report.Is there any way to give width and height dynamically for the sub report depending on the Progects size. Link to comment Share on other sites More sharing options...
shrije Posted October 22, 2008 Share Posted October 22, 2008 Subreports resize accordingly. You dont have to worry. Good that the JRBeanCollectionDataSource worked. i believe u missed the package name. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 24, 2008 Author Share Posted October 24, 2008 Hi,I am using IReport 3.0.1 and i want to represent my report in a Table format.How can i use could u please help me.In my IReport tool there is no Table field.Please help me. Link to comment Share on other sites More sharing options...
pnvswamy Posted October 24, 2008 Author Share Posted October 24, 2008 And I have one more doubt.Is there any way to execute the group in jrxml file depending on the Parameter.Eg: In java i have parameters like groupByEmp,GroupByDept like thisDepending on the Java Parameter i have to execute the Group of that parameter and remaining group will not execute.Is it possible. Link to comment Share on other sites More sharing options...
pnvswamy Posted November 4, 2008 Author Share Posted November 4, 2008 I am getting theException like Message Org.xml.sax.SAXParseException: Element type "pen" must be declared.Why it was happening.Please help me to resolve. Link to comment Share on other sites More sharing options...
xavixxxx Posted November 6, 2009 Share Posted November 6, 2009 Hello,I don't understand the solution gave to solve the problem :Errors were encountered when compiling report expressions class file:1. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getValue())));/*$JR_EXPR_ID=39$*/<------------------------>2. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getOldValue())));/*$JR_EXPR_ID=39$*/<------------------------>3. JRBeanCollectionDataSource cannot be resolved or is not a typevalue = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_projDetails.getValue())));/*$JR_EXPR_ID=39$*/<------------------------> I have the same problem on a subreport and I don't manage to solve it.Could you help me please ? 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