jakubhertyk Posted February 2, 2007 Share Posted February 2, 2007 Hello, I don't think that this is a unique problem to my report but I need to access the current row of the Parent report in the Sub-report. I have a report that generates a Sub-report for every Group Header. This Sub-report uses 12 variables from the current Group Header row of the Parent report. Rather than passing 12 parameters to the Sub-report, I thought that it would be simpler to access the current row of the Parent report where the fields reside. Is there anyway I can accomplish this? Thank you, Jakub :(Post edited by: jakubhertyk, at: 2007/02/01 22:10 Link to comment Share on other sites More sharing options...
christiaan_se Posted February 2, 2007 Share Posted February 2, 2007 Hi,you can write a custom datasource which has access to the parent datasource:Code:public class ChildDataSource implements JRDataSource { private JRDataSource parentDatasource = null; public ChildDataSource (ParentDataSource parentDatasource) { super(); this.parentDatasource = parentDatasource; } public Object getFieldValue(JRField field) throws JRException { Object parentObject = parentDatasource.getCurrentRowObject(); .... }} Link to comment Share on other sites More sharing options...
jakubhertyk Posted February 2, 2007 Author Share Posted February 2, 2007 Code:parentDatasource.getCurrentRowObject(); The following doesn't appear to be a valid method for JRDataSource. I can't even find one that resembles it. Also, what should I do in the next() method. Iterate the parentDataSource? Thanks, Jakub Link to comment Share on other sites More sharing options...
christiaan_se Posted February 9, 2007 Share Posted February 9, 2007 Yes sorry about that (and the late reply). It's just example code, not fully functional. The idea is that you provide a custom datasource for both parent and child. As soon next is being called you store that info in an attribute so the child CustomDataSource can easily access this. Code:public class CustomDataSource implements JRDataSource { private CustomDataSource parentDatasource = null; private Object currentObject = null; public ChildDataSource (ParentDataSource parentDatasource) { super(); this.parentDatasource = parentDatasource; } public Object getFieldValue(JRField field) throws JRException { if(parentDatasource != null) { Object parentObject = parentDatasource.getCurrentRow(); //now use parentObject to get parent info } //use currentObject to retrieve info } public boolean next() throws JRException { //process next data //assign data to currentObject } public Object getCurrentObject() { return currentObject(); }} hope this helps,Christiaan 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