【问题标题】:JRXML - Display a checkbox in a tableJRXML - 在表格中显示一个复选框
【发布时间】:2011-09-19 09:06:47
【问题描述】:

我无法在 jrxml 的表格中显示复选框。

这是我的代码示例:

<detail>
    <band height="45" splitType="Stretch">
        <textField isBlankWhenNull="true">
            <reportElement style="MyCustomStyle" stretchType="RelativeToTallestObject" x="650" y="0" width="80" height="35"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression class="java.lang.Boolean"><![CDATA[$F{myBooleanVariable}]]>
            </textFieldExpression>
        </textField>
    </band>
</detail>

该列仅显示 truefalse。我认为在 textFieldExpression 元素中指定 class="java.lang.Boolean" 会将值转换为复选框,但显然,我需要的不止这些。

知道我做错了什么吗?

【问题讨论】:

    标签: checkbox jasper-reports xmltable


    【解决方案1】:

    我刚刚在您已经制定的解决方案中添加了一些 unicode:

    <textFieldExpression><![CDATA[$F{myBooleanVairiable}? "\u2713":"\u2717"]]></textFieldExpression>
    

    u2713 转换为勾号,u2717 转换为十字

    记得确保你在你的xml页面顶部的编码语句设置为UTF8:

    【讨论】:

    • 不幸的是,当您将报告导出为 pdf 格式时,这似乎不起作用。我尝试了几种字体类型,但似乎没有一种可以工作。
    • 明确使用包含相关字形的字体。 PDF 导出中的字体在 Jasper 中是一种特殊的野兽。
    【解决方案2】:

    jasper HTML报告中的复选框可以如下

    <textFieldExpression><![CDATA[$F{myBooleanVairiable}? "\u2713":"\u2717"]]></textFieldExpression>
    

    注意:必须使用支持unicode的字体

    在 PDF 中不能使用上面的代码。我们要么必须使用字体扩展名,要么按如下方式绘制线条

    <frame>
    <reportElement x="161" y="73" width="12" height="12"/>
    <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
        <pen lineWidth="1.0"/>
        <topPen lineWidth="1.0"/>
        <leftPen lineWidth="1.0"/>
        <bottomPen lineWidth="1.0"/>
        <rightPen lineWidth="1.0"/>
    </box>
    <line>
        <reportElement x="2" y="7" width="2" height="2">
            <printWhenExpression><![CDATA[Boolean Exprssion]></printWhenExpression>
        </reportElement>
    </line>
    <line direction="BottomUp">
        <reportElement x="4" y="3" width="6" height="6">
            <printWhenExpression><![CDATA[Boolean Exprssion]]]></printWhenExpression>
        </reportElement>
    </line>
    

    【讨论】:

      【解决方案3】:

      简单,做这个,在标签上->imageExpression

              <componentElement>
                  <reportElement x="196" y="109" width="46" height="39"/>
                  <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                      <datasetRun subDataset="dataset3">
                          <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{fisicos})]]></dataSourceExpression>
                      </datasetRun>
                      <jr:listContents height="39" width="46">
                          <image>
                              <reportElement x="12" y="0" width="17" height="21"/>
                              <imageExpression><![CDATA[$F{_THIS} == true ? $P{checkboxFisicoOK} : $P{checkboxFisicoNOK}]]></imageExpression>
                          </image>
                      </jr:listContents>
                  </jr:list>
              </componentElement>
      

      • checkboxFisicoOK:是图片路径的参数。

        <parameter name="checkboxFisicoOK" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA[new java.lang.String("/Users/ccamol/onprocess/checkboxOK.jpg")]]></defaultValueExpression>
        </parameter>
        

      【讨论】:

      • 太棒了。那应该是公认的。只有一个细节:您必须定义 2 个参数:checkboxFisicoOK 和 checkboxFisicoNOK
      • 赞成添加图像...除了您的答案之外,此线程中没有人发布他们的代码输出。图片说话..
      【解决方案4】:

      好吧,显然不可能在使用该语言的表格中添加复选框!

      所以现在我只显示是/否:

      <textFieldExpression class="java.lang.String"><![CDATA[$F{myBooleanVariable}?"YES":"NO"]]></textFieldExpression>
      

      这是我能找到的最好的!

      【讨论】:

        【解决方案5】:

        对于 PDF 这对我有用,明确地将字体设置为支持 unicode 的字体:

        <textField>
            <textElement>
                <font fontName="DejaVu Sans" size="16"/>
            </textElement>
            <textFieldExpression><![CDATA[$F{myBooleanVariable}?"\u2611" : "\u2610"]]></textFieldExpression>
        </textField>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-02-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-10-08
          • 1970-01-01
          • 2018-02-01
          相关资源
          最近更新 更多