如果子报表为空,则隐藏文本字段

问题描述:

我在 Jasper 中创建了一个包含四个部分的报告。每个部分都包含一个文本字段作为标题和一个子报表。子报表可以为空。如果它为空,则使用空白时删除行隐藏它。到目前为止这个工作。现在,如果子报表被隐藏,也应该隐藏相应的标题文本字段。

I am creating a report in Jasper with four parts. Each part consists of a text field as the header and a subreport. The subreport can be empty. If it is empty it is hidden using Remove Line When Blank. This works so far. Now, the corresponding header text field should be hidden too if the subreport is hidden.

我尝试过很多东西,但无法提出解决方案。
例如使用打印表达式 new Boolean($ P {otherField} .read()!= -1)。这从未显示过标题。

I have tried many things but couldn't come up with a solution. E.g. using Print When Expression: new Boolean ($P{otherField}.read() != -1). This never showed the header.

我还试图在我的Java程序中隐藏标题但找不到合适的API命令。我猜 getBands()[x] .getChildren()[y] 引导我到正确的标题,但我无法将其隐藏在那里。

As well I tried to hide the header in my Java program but couldn't find an appropriate API command. I guess getBands()[x].getChildren()[y] lead me to the right header but I couldn't hide it there.

还有其他想法吗?

感谢您的帮助。我终于可以通过在标题中的Print When Expression下使用以下表达式来解决它:

Thank you for your help. I finally could solve it by using the following expression under "Print When Expression" in the header:

($P{SUBR}!=null)

其中


$ P {SUBR}

$P{SUBR}

是子报告的表达式。