Jump to content
JasperReports Library 7.0 is now available ×

Accessing row of datasource without subreport


olidel2003

Recommended Posts

Hi,

Answer is problably easy but... I've not found how to do this :(

 

From a Java app, I get a compliant JRDataSource object which contains fields (1 row, several fields). One of the fields is a JRDataSource too (for example SubElementsField) and it contains several rows and for each row several fields (for example SubElementField1).

 

Example

MainDataSource

--Field1 (String)

--Field2 (String)

--SubElementsField (JRDataSource)

-----SubElementField1

 

If I put a subreport in my main report with datasource SubElementsField, I can access in the subreport the field $F{SubElementField1} with this very easy syntax.

 

Now, what I want to do is to be able to access to SubElementField1 in my MAIN report through a syntax like $F{SubElementsField}[0]_F{SubElementField1}...

 

How can I do this... I don't want a sub-report, I just want to access the 3th field of the 1st row of SubElementsField in my main report (for example).

 

Which syntax can I use?

Thanks a lot.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Just create your own CustomDataSource and write your own public method that returns the fieldvalue of a given row number.

 

something like (just PseudoCode):

 

Code:
public Object getFieldValueByRowNumber(int rowNumber,String fieldName){

if (rowNumber>=0 && rowNumber <= datsource.getRecordCount() && fieldExist(fieldName){
return getRow(rowNumber).getFieldValue(fieldName);
}
}

 

quite easy (IMHO).

 

regards + hth

C-Box

Link to comment
Share on other sites

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...