2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Greg Greaves - ggreaves JRDataSource problem 2003-08-22 08:19 I have a report that uses a custom JRDataSource to fill it. When I run the report using a SQL connection to run the query, everything's fine. When I use my custom data source it doesn't print the last row of the report. I have put printlines in the datasource and found that: 1. next() is being called the right number of times (4 rows in the result set = 4 calls to next() ) 2. I put a println in getFieldValue() and found that it is NOT getting called for the last row. Any ideas what might be causing this? -Greg By: Gregory A. Swarthout - gswarthout RE: JRDataSource problem 2003-08-22 08:41 Show us the code to your custom JRDataSource and we might be able to help you. By: Greg Greaves - ggreaves RE: JRDataSource problem 2003-08-22 09:48 Here's the relevant code from the datasource including the constructor (that gets the results), the next() and the getFieldValue(): private int index = -1; static ReportsSession reportsSession = null; TransactionList resultList = null; VReportTestValueObject currentRecord = null; /** */ public ReportTestDataSource() { // Go to the application server and get the results resultList = this.provideAllVReportTest(); } /** *@return Description of the Return Value *@exception JRException Description of the Exception */ public boolean next() throws JRException { index++; // Get the next value object from the list (index starts at 0) currentRecord = (VReportTestValueObject)resultList.get(index); return (index < resultList.size() - 1 ); } /** *@param field Description of the Parameter *@return The fieldValue value *@exception JRException Description of the Exception */ public Object getFieldValue(JRField field) throws JRException { Object value = null; String fieldName = field.getName(); if ("C_ID".equals(fieldName)) { value = currentRecord.getCId(); } else if ("C_CASE_MANAGEMENT_FLAG".equals(fieldName)) { value = currentRecord.getCCaseManagementFlag(); } else if ("P_NAME_FIRST".equals(fieldName)) { value = currentRecord.getPNameFirst(); } else if ("P_NAME_LAST".equals(fieldName)) { value = currentRecord.getPNameLast(); } else if ("P_GENDER".equals(fieldName)) { value = currentRecord.getPGender(); } else if ("P_MARRIED".equals(fieldName)) { value = currentRecord.getPMarried(); } else if ("P_DATE_BIRTH".equals(fieldName)) { value = currentRecord.getPDateBirth(); } else if ("T_ID".equals(fieldName)) { value = currentRecord.getTId(); } else if ("T_TREATMENT_NO".equals(fieldName)) { value = currentRecord.getTTreatmentNo(); } else if ("T_RECORD_STATUS".equals(fieldName)) { value = currentRecord.getTRecordStatus(); } else if ("T_COST_PROPOSED".equals(fieldName)) { value = currentRecord.getTCostProposed(); } else if ("T_COST_ACTUAL".equals(fieldName)) { value = currentRecord.getTCostActual(); } else if ("DL_NAME".equals(fieldName)) { value = currentRecord.getDlName(); } else if ("FL_NAME".equals(fieldName)) { value = currentRecord.getFlName(); } else if ("M_MEMO_GROUP_ID".equals(fieldName)) { value = currentRecord.getMMemoGroupId(); } else if ("M_SUBJECT".equals(fieldName)) { value = currentRecord.getMSubject(); } else if ("M_MEMO".equals(fieldName)) { value = currentRecord.getMMemo(); } return value; } By: Gregory A. Swarthout - gswarthout RE: JRDataSource problem 2003-08-22 10:01 Think I found the problem. next() is being called 4 times, but the last time it is returning false: return (index < resultList.size() - 1 ); 3 < 4 - 1 = false Get rid of the -1. Then it will be called 5 times, 4 with true and once with false, which is what you want when there are 4 records. By: Gregory A. Swarthout - gswarthout RE: JRDataSource problem 2003-08-22 10:03 Of course, you'll also have to change the logic of this line: currentRecord = (VReportTestValueObject)resultList.get(index); So that it doesn't try to get a record if the index = resultList.size(). By: Greg Greaves - ggreaves RE: JRDataSource problem 2003-08-22 11:11 Thank you sir. You have been most helpful. -Greg 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