Displaying static text instead of empty group in J

2019-08-18 09:01发布

I have a Jasper report that displays a list of bill line items. These items are grouped by billing period, and then by whether the item is a charge or credit. For billing periods in which there are charges but no credits, I would like to display a static text field stating "No credits" in the Credit group for that period. How can this be done?

Edited to add: This is assuming that I am using an SQL query for the data source, as opposed to customizing one. If I customize my data source, I can handle this in pre-processing before I reach the report, but I was hoping to discover a way to get around Jasper's behavior of skipping groups with no rows meeting the group criteria.

1条回答
时光不老,我们不散
2楼-- · 2019-08-18 09:26

If you were able to, in your data source, have a count of total # of credits for each group, then you could use the 'print when expression' property on the static text. e.g:

new Boolean ($F{total_credits}.equals(0));

The static text would need to go in the group header or footer as it wouldn't work in the group detail section (it would print out multiple times).

You may need to create a variable instead of use $F{total_credits} directly - I'm not certain how JasperReports deals with accessing fields in group footers. You may also find that in the group header it picks up the correct total_credits while in the group footer it doesn't.

The other way would be to have a variable that counts the total # of credits in the group. You would need to set the 'reset type' for the variable to 'group', then set the reset group. The Variable expression would be something like:

$V{myvariable} + 
($F{credit_or_debit}.equals("credit") ? new Integer(1) : new Integer(0))

and the initial value expression would be new Integer(0)

Then in the group footer you could use the 'print when expression' on the static text to look at the variable.

查看更多
登录 后发表回答