JRXML - 在表格中显示复选框

发布于 2024-11-16 07:52:39 字数 826 浏览 2 评论 0原文

我无法在 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" 会将值转换为复选框,但显然,我需要不仅如此。

知道我做错了什么吗?

I can't manage to display a checkbox in a table in jrxml.

Here is a sample of my code:

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

The column just displays true or false. I supposed that specifying class="java.lang.Boolean" in the textFieldExpression element would convert the value to a checkbox but apparently, I need more than that.

Any idea of what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

温暖的光 2024-11-23 07:52:39

很简单,在标签上执行此操作 ->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:是图像路径的参数。

    <参数名称=“checkboxFisicoOK”类=“java.lang.String”isForPrompting=“false”>
        
    
    

Simple, do this, on the tag ->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>

enter image description here

  • checkboxFisicoOK: is a parameter of the image path.

    <parameter name="checkboxFisicoOK" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[new java.lang.String("/Users/ccamol/onprocess/checkboxOK.jpg")]]></defaultValueExpression>
    </parameter>
    
∞觅青森が 2024-11-23 07:52:39

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

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

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

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

I just added some unicode to the solution you already made:

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

u2713 translates to a tick mark and u2717 to a cross

Remember to make sure you're encoding statement at the top of your xml page is set to UTF8:

倾其所爱 2024-11-23 07:52:39

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>

Checkbox in the the jasper HTML report can be as follows

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

Note: Have to use the font which supports the unicode

In PDF above code cannot be used. Either we have to use font extension or by drawing lines as follows

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

時窥 2024-11-23 07:52:39

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

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

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

这是我能找到的最好的!

Al right so apparently it's not possible to add a checkbox in a table with that language !

So now I just display YES/NO:

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

That's the best I could find !

眉目亦如画i 2024-11-23 07:52:39

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

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

For PDF this worked for me, explicitly setting the font to one that supports unicode:

<textField>
    <textElement>
        <font fontName="DejaVu Sans" size="16"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{myBooleanVariable}?"\u2611" : "\u2610"]]></textFieldExpression>
</textField>
时光无声 2024-11-23 07:52:39

对 Olezt 答案的补充,“DejaVu Sans”字体或“Segoe UI Symbol”适用于勾选的复选框,包括通过导出为 pdf
Jasper Studio

要使其适用于 JaserReport Server,需要将字体添加到 Jasper Studio 和 Jasper Server。

  1. 从 Windows\font 或 Internet 获取字体的 ttf 文件。
  2. 在 Jasper Studio 中,窗口 -> 首选项 -> Jaspersoft Studio -> 字体
  3. 单击添加
  4. 输入字体的系列名称(例如 Segoe UI Symbol 1)
  5. 在 TrueType (.ttf) 中,浏览步骤 (1) 中获取的 ttf上面
  6. 勾选“在PDF文档中嵌入此字体”
  7. 在PDF编码中选择“Identity-H(横向书写的Unicode)”。
  8. 单击“下一步”(不要单击“完成”)
  9. 添加“html”、“rtf”、“xhtml”字体映射。字体名称应为上面步骤 (4) 中的名称。
  10. 单击完成
  11. 新添加的字体将显示在“首选项”窗口中。选择它并单击“导出”以获取 jar。这是要放到 Jasper 服务器上
  12. 将 jar 放入 jasper 服务器的“C:\Jaspersoft\jasperreports-server-cp-6.3.0\apache-tomcat\webapps\jasperserver\WEB-INF\lib”并重新启动服务器。
  13. 要添加复选框,请先找到“html 实体”。例如,☑ 表示已勾选的投票箱,而 ☐ 表示未勾选的投票箱。 https://www.compart.com/en/unicode/U+2611
  14. 返回 Jaspersoft Studio,在显示复选框的“文本字段”中,选择新添加的字体,然后为“标记”选择“html”。
  15. 生成、测试、部署并享受。

参考:https://community.jaspersoft.com/jasperreports-library/issues/13056< /a>

参考:https://community.jaspersoft.com/wiki/custom-font-font-扩展#Publish_the_Font_to_the_Server

Supplement to Olezt's answer, "DejaVu Sans" font, or "Segoe UI Symbol" works for ticked checkbox, including export to pdf through
Jasper Studio

To make it works for JaserReport Server, need to Add the font to both Jasper Studio and Jasper Server.

  1. Get the ttf file of the font, either from Windows\font or from Internet.
  2. In Jasper Studio, Window->Preference->Jaspersoft Studio->Fonts
  3. Click Add
  4. Input the Family Name of the font (e.g. Segoe UI Symbol 1)
  5. In TrueType (.ttf), Browse the ttf get in step (1) above
  6. Tick "Embed this font in PDF document"
  7. Select "Identity-H (Unicode with horizontal writing)" in PDF Encoding.
  8. Click "Next" (Don't click Finish)
  9. Add "html", "rtf", "xhtml" Font Mapping. The Font Name should be that in step (4) above.
  10. Click Finish
  11. The new added font is shown in the "Preferences" window. Select it and click "Export" to get the jar. This is to put to Jasper Server
  12. Put the jar to "C:\Jaspersoft\jasperreports-server-cp-6.3.0\apache-tomcat\webapps\jasperserver\WEB-INF\lib" of your jasper server and restart server.
  13. To add checkbox, find the "html entity" first. e.g. ☑ for Ballotbox with check, and ☐ for unchecked. https://www.compart.com/en/unicode/U+2611
  14. Back to the Jaspersoft Studio, in the "Text Field" showing the checkbox, select the newly added font, and select "html" for Markup.
  15. Generate, test, deploy, and enjoy.

Ref: https://community.jaspersoft.com/jasperreports-library/issues/13056

Ref: https://community.jaspersoft.com/wiki/custom-font-font-extension#Publish_the_Font_to_the_Server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文