Jump to content
Changes to the Jaspersoft community edition download ×

pass arg to bean datasource field accessor


2006 IR Open Dicussion

Recommended Posts

By: Jim Stoll - jim_stoll

pass arg to bean datasource field accessor

2006-03-06 18:47

I would like to pass an argument to a report field accessor method for a bean-based datasource. Ex, say I have a java.util.List or a simple array in my datasource bean, and would like to access values in that collection positionally, via a method such as getIndexedValue(int index)

 

I tried setting up a report field named indexedValue and accessing the field as $F{indexedValue(2)} for instance, but that's not working.

 

I can return the entire List or array by typing the report field as Object and casting as appropriate in my uses of the field in the report, but I don't want to suffer the overhead of pulling the whole list back on every call, especially since I need to do some processing on the value before it is returned (such as formatting numbers for currency, which I want centralized in the bean, not distributed through all of my reports)

 

I think that I need to coerce jasper to use the org.apache.commons.beanutils.PropertyUtils.getMappedProperty(Object, String, String), but don't know how...

 

Thanks

 

 

 

 

By: Jim Stoll - jim_stoll

RE: pass arg to bean datasource field accesso

2006-03-06 19:37

Hmm... I looked at a bit of the Jasper source code, and it doesn't appear that the current version will support keyed property access. (and it appears that the change would be kind of far reaching in the code)

 

That having been said, a little further experimentation makes it look liket either Jasper or Beanutils grabs the collection once and then provides local access to it in the report - Repeated calls to an Object-type report field named "listProperty", with a corresponding bean method "List getListProperty()", casting and accessing by position in the report such as "((java.util.List)$F{listProperty}).get(0).toString()" seems to result in only 1 hit against the bean's getListProperty() method, regardless of the number of indexed accesses of the List field, which alleviates my fears about repeatedly obtaining (and processing in the bean's get method) the list for each positional access.

 

Sorry to make this so long-winded, but I just want to lay it out so that someone in the know can confirm/deny that this is what is actually happening.

 

Thanks Again!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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