JRXML - 在表格中显示一个复选框

时间:2011-06-21 09:44:04

标签: checkbox jasper-reports xmltable

我无法在 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>

该列只显示 true false 。我认为在 textFieldExpression 元素中指定class="java.lang.Boolean"会将值转换为复选框,但显然,我需要更多。

知道我做错了什么?

5 个答案:

答案 0 :(得分:5)

我刚刚为您已经制作的解决方案添加了一些unicode:

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

u2713转换为刻度线,u2717转换为十字架

请记住确保您在xml页面顶部的编码语句设置为UTF8:

答案 1 :(得分:2)

简单,在标签上执行此操作 - &gt; imageExpression&lt; -

        <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>

enter image description here

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

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

答案 2 :(得分:1)

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

所以现在我只显示YES / NO:

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

这是我能找到的最好的!

答案 3 :(得分:1)

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>

答案 4 :(得分:0)

对于PDF来说,这对我有用,将字体显式设置为支持unicode的字体:

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