salvuzzo87 Posted February 13, 2012 Share Posted February 13, 2012 Hello Boys, sorry for my english. I Have one problem with Jasper Report. I Must print two collection Object, but I have not one basic Database. I have seen that you can insert in one jasper report only JRBeanCollectionDataSource. I Can transfer two list with parameters ? I have see that one parameters can be one java.util.collection, but for iterate one collection of a one parameters how do? Thanks ^^ Link to comment Share on other sites More sharing options...
salvuzzo87 Posted February 14, 2012 Author Share Posted February 14, 2012 Code:no one can help me? Link to comment Share on other sites More sharing options...
sanbez Posted February 15, 2012 Share Posted February 15, 2012 I don't understood your questions exactly. If you want to display parameter-collection in report, you mast make subreport with DataSource expression like this: new YourClassNameDataSource($P{paramCollectionName})where $P{paramCollectionName) - parameter of main report and class YourClassNameDataSource must implements JRDataSource interface Link to comment Share on other sites More sharing options...
salvuzzo87 Posted February 20, 2012 Author Share Posted February 20, 2012 I need to spend 3 collections with the parameters, you can not connect to the database? Link to comment Share on other sites More sharing options...
sanbez Posted February 21, 2012 Share Posted February 21, 2012 salvuzzo87Wrote: I need to spend 3 collections with the parameters, you can not connect to the database? >> I need to spend 3 collections with the parametersUse 3 params and 3 subreports :)you can not connect to the database?I don't understand. In my reports all information is saved in collections. I am don't need connect to database Link to comment Share on other sites More sharing options...
salvuzzo87 Posted February 21, 2012 Author Share Posted February 21, 2012 Ok, but i have created 3 subreport. I Mean. I use as programming languages JAVA. In one action i have 3 collections, this colletions i put them one hashmap. Now, in the subreports, how do to work this collections? If use one JRBeanCollectionDataSource in jasper report i create field with name equal the field the collections, but i can use one JRBeanCollectionDataSource, the other collections i put them parameters . In jasper report how do to iterate the other collections? Link to comment Share on other sites More sharing options...
sanbez Posted February 22, 2012 Share Posted February 22, 2012 In my first message i wrote about DataSource expression for subreport and JRDataSource interface for this class. My example:for subreport datasource expression in main report:--- cutnew R1250DataSource($F{ascueGroup}, $P{startDate}, $P{endDate})--- end cutwhere $F{ascueGroup} - field from main report, $P{startDate}, $P{endDate} - params of main reportIn your case you may use map as parameter of constructor for dataSource for subreport And for iterate on collection in subreport you must inmplements JRDataSource interface (realize methods next() and getFieldValue())(@see net.sf.jasperreports.engine.JRDataSource ) --- my code for examplepublic class R1250DataSource implements JRDataSource { private PredictedExpense currentPredictedExpense;private Iterator<PredictedExpense> iterator; // constructorpublic R1250DataSource(Group group, Date startDate, Date endDate) throws JRException { List<PredictedExpense> values = new ArrayList<PredictedExpense>();try { .... vaues.add(new PredictedExpense(...)); } catch (NullPointerException e) { throw new JRException(e);}iterator = values.iterator();} @Override public boolean next() throws JRException{ boolean result = iterator.hasNext(); if (result) { currentPredictedExpense = iterator.next(); } return result; } @Override public Object getFieldValue(JRField jrf) throws JRException { ExpenseMeasureChannel counterIndication = currentPredictedExpense.getCounterIndication(); if (jrf.getName().equals("pointName")) { return counterIndication.getAccountPointName();} if (jrf.getName().equals("counterName")) {return counterIndication.getCounterName();} ...return null;} and in subreport define fields with names "pointName", "counterName", ... Good luck Link to comment Share on other sites More sharing options...
salvuzzo87 Posted February 22, 2012 Author Share Posted February 22, 2012 I am not clear, JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(myList); the compile my report and then fill my report. In my XML (generate with tool jasperreport), i have field whit name equal to those on my list. But for each repoirt i can pass only CollectionsDataSource. The other list they step paramters just?Ok, in my XML as recovery values ? If I create field with name equal to thos on my list that i pass with paramters does not work because the field work only CollectionDatasource... Link to comment Share on other sites More sharing options...
sanbez Posted February 22, 2012 Share Posted February 22, 2012 Additional explanations:You may use even empty dataSource for main report:JRDataSource dataSource = new JREmptyDataSource(); and solve any problems on params and subreports 1. Make subreport (subreport.jrxml)2. Modify main report (main.jrxml), inserting subreport into detail (or summary? band)3. Define parameter1 as java.util.collection for main report4. Pass list to parameter1 of main report (in java-code).5. For element "subreport" of main report define dataSource expression: new YourClass($P{parameter1})6. Implements JRDataSource interface in YourClass where getFieldValue returns field as they named (and with this types as in subreport. see 1.Make subreport) If this is not clear, please put screenshot of desired reportThe way to solution your problems may be various for different "structure" of your report Link to comment Share on other sites More sharing options...
salvuzzo87 Posted February 22, 2012 Author Share Posted February 22, 2012 I did not understand the point 5 Link to comment Share on other sites More sharing options...
sanbez Posted February 22, 2012 Share Posted February 22, 2012 See DataSource expression in R1250.jrxml for calling subreportSorry for double post Post Edited by sanbez at 02/22/2012 15:44 Link to comment Share on other sites More sharing options...
sanbez Posted February 22, 2012 Share Posted February 22, 2012 See DataSource expression in R1250.jrxml 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