Jump to content
Changes to the Jaspersoft community edition download ×

Getting current object

Recommended Posts

By: Morten Kristiansen - mortenkr

Getting current object

2006-05-03 06:43

I'm currently using a Collection with objects as DataSource to a Jasper report. Are there any way to get the current object in this datasource? I need something like $R{currentObject}. The reason for this is that my objects in the Collection, does not have any get methods, but methods like "getValue(String key)". So when displaying values in report i need to do this: $R{current}.getValue("myKey").

Link to comment
Share on other sites

  • 6 months later...
  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

I'm kind of desperate here... I'm thinking of declaring a method "getMe()" that returns the current instance, so that I can declare a field "me", and through "me" access the stuff I want to access.


Of course, this horrible horrible thing implies messing up my code :( ...


Does anyone have a better idea to stop this!!!???


Thanx again

Link to comment
Share on other sites

The JR bean collection data source does not support this.


However, you could easily extend JRBeanCollectionDataSource to return the current bean for fields mapped to "this" (for instance):


public class MyBeanCollectionDataSource extends JRBeanCollectionDataSource {
static final String BEAN_MAPPING = "this";
protected Object getFieldValue(Object bean, JRField field) throws JRException {
String prop = getPropertyName(field);
Object value;
if (prop.equals(BEAN_MAPPING)) {
value = bean;
} else {
value = super.getFieldValue(bean, field);
return value;




Link to comment
Share on other sites

  • 3 months later...

We have included this functionality in the core JR code. Bean data sources (JRBeanCollectionDataSource and JRBeanArrayDataSource) yield the current bean as value for fields mapped to _THIS (the mapping is case sensitive):


<field name="_THIS" class="com.domain.MyBean"/>
<!-- OR -->
<field name="myBean" class="com.domain.MyBean">


This change is currently on the JR SVN trunk and will be part of the next release.




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