tranvi3t Posted June 14 Share Posted June 14 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 More sharing options...
Mehak Rajkumar Posted June 15 Share Posted June 15 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 More sharing options...
lucianc Posted June 15 Share Posted June 15 You can specify the mapping of a report field to a property name in the Java class using the net.sf.jasperreports.javabean.field.property property.For instance <field name="customer_name" class="java.lang.String"> <property name="net.sf.jasperreports.javabean.field.property" value="customerName"/> </field>[/code]Regards,Lucian Link to comment Share on other sites More sharing options...
tranvi3t Posted June 16 Author Share Posted June 16 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 More sharing options...
lucianc Posted June 16 Share Posted June 16 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 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