augarte Posted February 13, 2013 Share Posted February 13, 2013 Hi! I'd like to export some reports to use JavaBean datasources (so far I have been using xml datasources). Mi idea was to create "Field" class wich will have two attributes: "name" and "value". So in my datasources I'll have a list of "Field" class, each one with its "name" and "value". My problem is that I don't know how to retrieve the values I want to add them to the report. For example, if I want to get the"value" of the "Field" which "name" is "Prj", but how to define the field description in order to get this value? I have been thinking about it. Maybe an option is to create another Bean that has a list of objects of "Field" type, and implement a function getValueByName (String name) that iterates all the "Field" list and returns the value of the one that matches with the given name. But don't know how to do it. Is this possible?I'm a bit lost, so any help will be very appreciated. Best regards!Aitor Link to comment Share on other sites More sharing options...
augarte Posted February 14, 2013 Author Share Posted February 14, 2013 Maybe it was not very clear what I want to do in the previous explanation. In the report I have working, I have a xml file with the structure you can see in the following link: http://pastebin.com/s3y8K0eeThen, if I want to to define a field, I can do it using XPATH as follows: Column[@name=OPENUM]/@value . With this I can have in a field the value of any column which name is "xxxx" (OPENUM in this case). The aim of these is to have the same datasource structure for all the reports. What I want to do now is to have something similar but without using intermediate xml files. So I want a generic way to get the data from the database, map it to some objects and pass these data to the report. My first idea was to use JavaBeanDatasource but don't know how to get the fields. For xml I have XPATH which helps me a lot when getting the field values, but don't know how to do something similar with JavaBeanDatasource. Is it possible? Does anybody know how could I do it? Thanks in advance!Best regards!Aitor Link to comment Share on other sites More sharing options...
sanbez Posted February 18, 2013 Share Posted February 18, 2013 I am don't understand exactly yuor questions. Is OPENUM private field must be present in all javaBean? Example: public class A1() {private String openum; public String getOpenum(); private String field2;} public class B1 { private String openum; public String getOpenum();private String field3; ...} This two different classes. You want to use it's in JRBeanCollectionDataSource for ONE report. Is I am understand correctly? In this way you can rewrite classes with using inheritance: public class Parent { private String openum; public String getOpenum(); } public class A1 extends Parent {private String field2; } public class B1 extends Parent { private String filed3; }Collection src = new ArrayList(); src.add(new A1(...)) src.add(new A1(...)) JRBeanCollectionDataSource dest = new JRBEanCollectionDataSource(src); - use it for first report or Collection src = new ArrayList(); src.add(new B1(...)) src.add(new B1(...)) JRBeanCollectionDataSource dest = new JRBEanCollectionDataSource(src); - use it for same report Link to comment Share on other sites More sharing options...
sanbez Posted February 18, 2013 Share Posted February 18, 2013 Collection src in all cases declared as Collection 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