问题
I am having a problem in jasper reports regarding designing a document template. It's like a resume.
I have this document:
Title [static text]
Age [static text] | [some field A]
Gender [static text] | [some field B]
Location [static text] | [some field C]
The current structure of my jasper reports is this:
I have this frame A, which has a vertical layout. Every row in the template (age, gender, location) corresponds to the frame I've created frames 1, 2 and 3.
Say, frame 1 has horizontal layout with 'Age [static text]' and '[some field A]' as its contents. The applies to frames 2 and 3.
Frame 1 has a position type of fix relative to top, while frames 2 and 3 are in float.
I want the row gender be hidden and be moved upwards if [some field] B is null or empty. How can I do that?
I've tried working on Remove Line When Blank but it only works inside a frame which has several fields in it. Basically, I want frame 1 to be hidden and have frames 2 and 3 be moved upwards if [some field A] is null or empty.
I hope for the soonest response.
回答1:
To achieve you desired result set:
positionType="Float"
on thereportElement
inside theframe
(it needs to move on the basis of the other elements.isRemoveLineWhenBlank="true"
, to remove it if its not visible according toprintWhenExpression
Include the check for all the fields inside the frame in the
printWhenExpression
es.new Boolean($F{field1}==null || $F{field2}==null || $F{field3}==null)
Example
<frame>
<reportElement positionType="Float" x="13" y="12" width="287" height="35" isRemoveLineWhenBlank="true" uuid="ee6707a4-bcb4-402b-95c0-6f4613747d2f">
<printWhenExpression><![CDATA[new Boolean($F{field1}==null || $F{field2}==null || $F{field3}==null)]]></printWhenExpression>
.. your textFields ...
</reportElement>
</frame>
NOTE: for compatibility with jasper report 3 and jdk 1.4 I have used new Boolean(...) this is not necessary in jasper report 5,6
来源:https://stackoverflow.com/questions/34126032/jasperreports-hide-frame-b-within-frame-a-if-one-the-fields-inside-frame-b-is