Escape dollar ($) sign in jasper report

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 ?

Answers


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


Need Your Help

Web App Libraries empty in Eclipse - no "jars" found

java eclipse spring jar

Recently my Spring MVC Java app, developed in Eclipse Indigo, seemed to lose it's connection to my "lib" folder where all my jars are (there were no jars found for my project anymore).

IIS app pool recycle + quartz scheduling

c# asp.net iis quartz.net

I'm running a web app on IIS 7.5 and it needs to recycle occasionally (otherwise memory usage gets out of handing, something i'm looking into!).