2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 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 More sharing options...
kriegerd Posted March 13, 2007 Share Posted March 13, 2007 I'm having the same problem!!... I need the current object in a Pojo datasource. If anyone knows this I would really appreciate it. Thanx in advance Link to comment Share on other sites More sharing options...
kriegerd Posted March 13, 2007 Share Posted March 13, 2007 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 More sharing options...
lucianc Posted March 13, 2007 Share Posted March 13, 2007 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):Code: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; }} HTH,Lucian Link to comment Share on other sites More sharing options...
kriegerd Posted March 13, 2007 Share Posted March 13, 2007 thanx.. it's been very useful.Thanx a lot. Link to comment Share on other sites More sharing options...
lucianc Posted June 26, 2007 Share Posted June 26, 2007 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):Code:<field name="_THIS" class="com.domain.MyBean"/><!-- OR --><field name="myBean" class="com.domain.MyBean"> <fieldDescription>_THIS</fieldDescription></field> This change is currently on the JR SVN trunk and will be part of the next release. Regards,Lucian 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