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 ?

有帮助吗?

解决方案

I found way to resolve this issue, it's a bug in Dynamic Jasper I think because Jasper need to name the field exactly as the column name and use this field as the TextExpression.

So to avoid doing this we need to override this function and using customExpression so the code need to be changed to this :

                    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();

This will resolve the problem for all the special chars. I will show you how the JRXML file will look as if we made this modification just to understand the concept :

It will be changed from :

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

To

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

Hope this will help someone :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top