2013-09-23 72 views
0

我有静态的文本在下面的其他显示一个staticText元素的列表:如何删除空值?

A 
B 
C 
D 
E 

我需要的元素的情况下崩溃其中一些不会被打印显示一个JasperReports的报告的列表。 (这些静态文本是标签,如果相应的值在表达式中打印时不会被打印)

示例:如果B为null,则输出应该如下所示。 (C,d,E应该向上浮动)

A 
C 
D 
E 

我一直没能得到它使用性质的工作,例如删除线当空位置类型为浮动等没有property 空白时为空为静态文本,就像那里的文本字段。这个东西适用于文本字段。

我想出了示例代码。请让我知道,如果这种情况下有什么问题:

<detail> 
     <band height="170" splitType="Stretch"> 
      <staticText> 
       <reportElement uuid="df801bc0-7c70-42c3-bc34-a8d735a96388" positionType="Float" x="88" y="15" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[A]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="bdeb24d3-74b9-4b93-a2ad-451732e500b5" positionType="Float" x="88" y="35" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[B]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="e68dc5fd-ed4f-46e0-aa5d-be1edc652aa3" positionType="Float" x="88" y="55" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="0b7481b2-33cd-4573-84b2-4a6738ca0ee3" positionType="Float" x="88" y="75" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[D]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="2b45cded-10f3-46b5-a87b-5c844e61b247" positionType="Float" x="88" y="95" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[E]]></text> 
      </staticText> 
     </band> 
    </detail> 

有没有人解决过这个问题?

+0

如果你正在谈论*静态文本*,是什么理由添加这个元素的* Null *值?你可以发布* jrxml *文件吗? –

+0

正如我所说,“这些静态文本是标签,如果相应的值为null时使用打印表达式时不会打印” - 我有一个表单元素列表'Label:Value',如果值为标签,则不显示标签为空 – anon

+1

您能否与我们分享您的jrxml?这将使诊断问题变得更容易。 – GenericJon

回答

0

请将每个'标签:值'放在单独的细节带中,如果在整个细节上表达,请使用打印。

0

您应该设置isPrintRepeatedValues属性值静态文本空字符串。

JRXML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="remove_empty_static" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e6315839-7098-4914-a0c9-a602d8a05d59"> 
    <title> 
     <band height="170" splitType="Stretch"> 
      <staticText> 
       <reportElement uuid="df801bc0-7c70-42c3-bc34-a8d735a96388" positionType="Float" x="88" y="15" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[A]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="bdeb24d3-74b9-4b93-a2ad-451732e500b5" positionType="Float" x="88" y="35" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[B]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="e68dc5fd-ed4f-46e0-aa5d-be1edc652aa3" positionType="Float" isPrintRepeatedValues="false" x="88" y="55" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
      </staticText> 
      <staticText> 
       <reportElement uuid="0b7481b2-33cd-4573-84b2-4a6738ca0ee3" positionType="Float" x="88" y="75" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[D]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="2b45cded-10f3-46b5-a87b-5c844e61b247" positionType="Float" x="88" y="95" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <textElement/> 
       <text><![CDATA[E]]></text> 
      </staticText> 
     </band> 
    </title> 
</jasperReport> 

其结果将是(通过预览在iReport的):

enter image description here

我不知道为什么,但它的工作原理: )

我用Java代码测试了这个示例 - 结果是相同的。

0

尝试用printWhenExpression

字段名称(类型字符串):firstName

 <staticText> 
      <reportElement x="60" y="185" width="130" height="20" uuid="6d98f418-7f61-42ca-ac96-aea325e2aad1"> 
       <printWhenExpression><![CDATA[$F{firstName} != null]]></printWhenExpression> 
      </reportElement> 
      <text><![CDATA[FirstName:]]></text> 
     </staticText> 

     <textField isBlankWhenNull="true"> 
      <reportElement x="265" y="222" width="181" height="20" uuid="4a04a05a-424a-47f1-a9f9-eecc9c7120c1"> 
       <printWhenExpression><![CDATA[$F{firstName} != null]]></printWhenExpression> 
      </reportElement> 
      <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression> 
     </textField> 

对于显示列表

 <textField isBlankWhenNull="true"> 
      <reportElement x="0" y="11" width="545" height="17" uuid="8f1b435d-40f4-4e59-a357-b3c2fcc38811"> 
      <printWhenExpression><![CDATA[$F{_THIS} != null]]></printWhenExpression> 
      </reportElement> 
      <textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression> 
     </textField> 
相关问题