如何为静态文本应用样式类?

时间:2014-02-15 11:29:19

标签: java jasper-reports

我在导出报告时通过JRHtmlExporterParameter.HTML_HEADER注入样式类。 在jrxml文件中,我将字段的样式名称设置为NonPrintable,它在html标题中可用。但在填充报告时,jasper会抛出以下异常。

net.sf.jasperreports.engine.JRRuntimeException: Could not resolve style(s): NonPrintable
at net.sf.jasperreports.engine.fill.JRFillObjectFactory.checkUnresolvedReferences(JRFillObjectFactory.java:1577)
at net.sf.jasperreports.engine.fill.JRFillObjectFactory.setStyles(JRFillObjectFactory.java:1504)
at net.sf.jasperreports.engine.fill.JRBaseFiller.loadStyles(JRBaseFiller.java:1000)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:879)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:569)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:915)
at com.echain.ireportapp.ReportGenerator.generateHtml(ReportGenerator.java:153)
at com.echain.ireportapp.ReportGenerator.generateReport(ReportGenerator.java:47)
at com.echain.ireportapp.IReportForm.generateReport(IReportForm.java:329)
at com.echain.ireportapp.IReportForm.runMouseClicked(IReportForm.java:66)
at com.echain.ireportapp.IReportForm.access$2(IReportForm.java:63)
at com.echain.ireportapp.IReportForm$4.mouseClicked(IReportForm.java:140)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6266)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

以下是我的jrxml

的样本
<textField isBlankWhenNull="true" hyperlinkType="LocalAnchor">
            <reportElement uuid="b292d262-c6af-46ed-99b7-af6335df205a" key="tfToHide" style="NonPrintable" x="852" y="0" width="100" height="19" forecolor="#192FC5"/>
            <textElement textAlignment="Right" verticalAlignment="Middle" markup="html">
                <font isBold="true"/>
            </textElement>
            <textFieldExpression><![CDATA["Bottom"]]></textFieldExpression>
            <anchorNameExpression><![CDATA["Top"]]></anchorNameExpression>
            <hyperlinkAnchorExpression><![CDATA["Bottom"]]></hyperlinkAnchorExpression>
        </textField>
        <textField isBlankWhenNull="true" hyperlinkType="Reference">
            <reportElement uuid="b292d262-c6af-46ed-99b7-af6335df205a" key="tfToHide" style="NonPrintable" x="0" y="0" width="100" height="19" forecolor="#192FC5"/>
            <textElement textAlignment="Left" verticalAlignment="Middle" markup="html">
                <font isBold="true"/>
            </textElement>
            <textFieldExpression><![CDATA["Back"]]></textFieldExpression>
            <hyperlinkReferenceExpression><![CDATA[$F{REQUESTEDURL}]]></hyperlinkReferenceExpression>
        </textField>

以下是导出设置

exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "<style type=\"text/css\" media=\"print\">"
                    + ".NonPrintable{display: none;}</style>");

我在设计部件/出口部件中遗漏了什么? 请建议我获得结果。

1 个答案:

答案 0 :(得分:2)

为要设置样式类的每个字段添加以下属性

net.sf.jasperreports.export.html.class

上述键的值是您的样式类名称。 在上面的问题中,我提到了类名为“NonPrintable”。所以上述键的值为NonPrintable

enter image description here