Jump to content
Changes to the Jaspersoft community edition download ×

How to map property names in POJO to field name .jrxml file ?


tranvi3t

Recommended Posts

Hi everyone,
I'm using JasperReports library to generate reports from my Java classes. I'm wondering if there is a way to map property names in my Java classes to field name in the .jrxml report template file, instead of having to follow the exact field names in the .jrxml?
For example, I may have a Java class with a field "customerName", but in the .jrxml file I want the field to be called "customer_name" instead. Is there a way to specify this mapping, so I don't have to change my Java class field names?
Does there exist any annotation like @Field that can achieve this?
Any help would be greatly appreciated.

Thank you!

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.
 

Link to comment
Share on other sites

I appreciate the suggestion. However, my issue is that I need to map the property names in the Java class to the field names in the .jrxml report template file, instead of the other way around. I'm exploring other options, such as creating a custom data source or using a third-party library that supports this type of mapping. Thank you for your help

Link to comment
Share on other sites

JasperReports relies on the JavaBeans standard to resolve object properties (via Commons Beanutils), so you can use the mechanisms defined in the standard to register property names to be resolved from reports.

For instance you can create a BeanInfo class and define the customer_name property:

public class CustomerBeanInfo extends SimpleBeanInfo {    @Override    public PropertyDescriptor[] getPropertyDescriptors() {        try {            return new PropertyDescriptor[] {new PropertyDescriptor("customer_name", Customer.class, "getCustomerName", null)};        } catch (IntrospectionException e) {            throw new RuntimeException(e);        }    }}[/code]

 

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