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?
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:
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>
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>
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>
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 !
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>
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.
- Get the ttf file of the font, either from Windows\font or from Internet.
- In Jasper Studio, Window->Preference->Jaspersoft Studio->Fonts
- Click Add
- Input the Family Name of the font (e.g. Segoe UI Symbol 1)
- In TrueType (.ttf), Browse the ttf get in step (1) above
- Tick "Embed this font in PDF document"
- Select "Identity-H (Unicode with horizontal writing)" in PDF Encoding.
- Click "Next" (Don't click Finish)
- Add "html", "rtf", "xhtml" Font Mapping. The Font Name should be that in step (4) above.
- Click Finish
- 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
- 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.
- 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
- Back to the Jaspersoft Studio, in the "Text Field" showing the checkbox, select the newly added font, and select "html" for Markup.
- 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
精彩评论