Jump to content
Changes to the Jaspersoft community edition download ×

Conditional fields?


caulfield14

Recommended Posts

My report contains a collection typed as a superclass which has two subclasses. Subclass 1 has a name property. Subclass 2 has a nameMessageCode property which contains a message code to be retrieved from the localized message property file.

 

In order to get reference the properties of the subclasses, the name and nameMessageCode properties are declared in <field> tags.

 

However, when the report is run, JR checks to see that all the defined fields exist on the object, regardless whether the field is used. I was going to use a conditional to display the name field for objects of subclass 1 or str(${nameMessageCode}) for objects of subclass 2.

 

Unfortunately, JR dies looking for the nonexistent nameMessageCode property on sublclass 1 objects or the nonexistent name property on subclass 2 objects.

 

Is there a way to prevent JR resolving fields until they are acutally used?

 

Thanks!

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

You could use your own data source implementation if the provided one does not work as you expect.

In JasperReports, if you declare a report field, it means you are alreay using it, just because it is declared.

You could subclass the data source implementation and make it silently ignore inexistant properties in the beans.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 3 weeks later...

I am interested in the implementation of this since I have the same problem. Right now, I have reports fields called field1, field2, field3, etc. If I don't provide it with field3, I get an "Unknown column name : FIELD3" exeception. I am passing in a JRResultSetDataSource. Does this mean, I sould have a fieldless jrxml file and somehow pass in the fields?

 

Thanks.

Link to comment
Share on other sites

I am interested in the implementation of this since I have the same problem. Right now, I have reports fields called field1, field2, field3, etc. If I don't provide it with field3, I get an "Unknown column name : FIELD3" exeception. I am passing in a JRResultSetDataSource. Does this mean, I sould have a fieldless jrxml file and somehow pass in the fields?

 

Thanks.

Link to comment
Share on other sites

I am interested in the implementation of this since I have the same problem. Right now, I have reports fields called field1, field2, field3, etc. If I don't provide it with field3, I get an "Unknown column name : FIELD3" exeception. I am passing in a JRResultSetDataSource. Does this mean, I sould have a fieldless jrxml file and somehow pass in the fields?

 

Thanks.

Link to comment
Share on other sites

In JasperReports, if you declare a report field, it means you are alreay using it, just because it is declared.

You could subclass the data source implementation and make it silently ignore inexistant properties in the beans.

 

Yeah, I was afraid of that.

 

The problem is that I am sending a List instead of a JR DataSource. The list contains Entities retrieved from Hibernate. I found a workaround with my entities rather than trying to extend the DataSource.

 

Thanks for the confirmation though.

g.

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