2

I would like to know if there is a way to escape dollar ($) sign in JasperReport (I'am using Dynamic Jasper) I tried the unicode and xml escape but it doesn't work.

I get this error :

1. Syntax error on token "$F", { expected
            value = $F{$}; //$JR_EXPR_ID=13$
                    <>

The Dynamic Jasper Report Code is :

    drb.setTitle(screenTitleData) 
        .setSubtitle(styledSubTitle)
        .setTitleStyle(titleStyle).setTitleHeight(new Integer(30))
        .setSubtitleHeight(new Integer(20))
        .setDetailHeight(new Integer(8))//defines the height for each record of the report
        .setMargins(margin, margin, margin, margin)
        .setDefaultStyles(titleStyle, null, headerStyle, columDetail)
        .setPrintBackgroundOnOddRows(true)
        .setOddRowBackgroundStyle(oddRowStyle)
        .setColumnsPerPage(new Integer(1))//defines columns per page (like in the telephone guide)
        .setColumnSpace(new Integer(5))
        .setWhenNoData(SwtConstants.DYNAMIC_JASPER_NO_DATA_FOUND, null,true,true)
        .setQuery(queryResult.getExecutedQuery(), DJConstants.QUERY_LANGUAGE_SQL);

as you see i'm using "setQuery" I have the list of columns saved in a object, so I browse the list to create the columns using this code :

// Varchar columns will not be styled
                abstractColumn = ColumnBuilder.getNew()
                        .setColumnProperty(columns.get(i).getColumnLabel(), String.class.getName())
                        .setTitle(columns.get(i).getColumnLabel()).setWidth(85)
                        .setStyle(commonStyle).setHeaderStyle(headerStyle)
                        .build();

if you want to reproduce this error just type a query like :

Select '$' from dual

Please note that the same error occur with "}" char too.

Can anyone help me please ?

4

1 回答 1

1

我找到了解决此问题的方法,我认为这是 Dynamic Jasper 中的一个错误,因为 Jasper 需要将字段完全命名为列名并将此字段用作 TextExpression。

所以为了避免这样做,我们需要重写这个函数并使用 customExpression 所以代码需要更改为:

                    abstractColumn = ColumnBuilder.getNew()
                        .setColumnProperty(columns.get(i).getColumnLabel(), String.class.getName())
                        .setTitle(columns.get(i).getColumnLabel()).setWidth(85)
                        .setStyle(commonStyle).setHeaderStyle(headerStyle)
                        .setCustomExpression(new CustomExpression() {
                            public Object evaluate(Map fields, Map variables,   Map parameters) {
                                return (String) fields.get(columnName);
                            }

                            public String getClassName() {
                                return String.class.getName();
                            }
                        })
                        .build();

这将解决所有特殊字符的问题。我将向您展示 JRXML 文件的外观,就好像我们进行此修改只是为了理解概念一样:

将从:

<textFieldExpression><![CDATA[$F{$$}]]>

<textFieldExpression><![CDATA[((ar.com.fdvs.dj.domain.CustomExpression)$P{REPORT_PARAMETERS_MAP}.get("customExpression_for_DJR_3068_COLUMN_1")).evaluate( ((ar.com.fdvs.dj.core.DJDefaultScriptlet)$P{REPORT_SCRIPTLET}).getCurrentFiels(), ((ar.com.fdvs.dj.core.DJDefaultScriptlet)$P{REPORT_SCRIPTLET}).getCurrentVariables(), ((ar.com.fdvs.dj.core.DJDefaultScriptlet)$P{REPORT_SCRIPTLET}).getCurrentParams() )]]></textFieldExpression>
        </textField>

希望这会对某人有所帮助:)

于 2014-02-04T10:38:57.230 回答