Jump to content
Changes to the Jaspersoft community edition download ×

Missing first record using JRDataSource


lesoft

Recommended Posts

Hi,

 

I'm using iReport to design my report. The report is using a custom data source which implemnts JRDataSource. I noticed that the first record in the list is alway missing in the report display. When stepped through debugger, the next() method below got called before calling getFieldValue() method. How do I prevent the skipping of first record (index = 0)?

 

I must have missed something very obvious here, but I couldn't figure out.

 

 

Code:

/**
* JasperReport library
*/
public class LineItemDataSourceVo implements JRDataSource {
/**
* Class variables
*/
private List<LineItemVo> data = null;
private int index = 0;

/**
* Default constructor
*/
public LineItemDataSourceVo(List<LineItemVo> items) {
this.data = items;
}

public void add(LineItemVo item) {
if (data == null) {
data = new ArrayList();
}

data.add(item);
}
/**
* =====================================================
* Required JRDataSource implementation methods
* =====================================================
*/
public boolean next() throws JRException {
index++;
return (index < data.size());
}

public Object getFieldValue(JRField field) throws JRException {
LineItemVo lineItem = (LineItemVo)data.get(index);
Object value = null;
try {
Object[] args = { };
Class[] paramTypes = { };
Class lineItemClass = lineItem.getClass();
Method getMethod = lineItemClass.getDeclaredMethod(field.getName(),
paramTypes);
value = "" + getMethod.invoke(lineItem, args);
} catch (Exception e) {
throw new JRException(e.getMessage());
}
return value;
}

} // LineItemDataSourceVo

 

Code:
[code]
LineItemDataSourceVo lineItemDS = new LineItemDataSourceVo(testData.getLineItems());
// ...some more code
JasperRunManager.runReportToPdfStream(reportStream,
response.getOutputStream(), parameters, lineItemDS);

 

Thanks,

Tuan

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...