Ask Question

How to conditionally render an element with JasperReports?

I want to render a specific element in my jasper report only if a specific condition is met in my data model, what is the best way to achieve this?



Authorยดs Dominik Sumer image

Dominik Sumer

Last edited on

1 Answer available

Best answer

In my specific case it helped to add a <printWhenExpression> element as a child of the <band> element I wanted to hide conditionally.

You can write an expression into the <printWhenExpression> Tag and only when this expression is met the element will be rendered. Here is an example where the expression checks if the specific String as hat least one character.

  <printWhenExpression><![CDATA[$F{myString}.length() > 0]]></printWhenExpression>