我想知道是否有办法逃避美元($)登录JasperReport(我使用动态Jasper)我尝试了unicode和xml转义但它不起作用。
我收到此错误:
1. Syntax error on token "$F", { expected
value = $F{$}; //$JR_EXPR_ID=13$
<>
动态Jasper报告代码是:
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);
如你所见,我正在使用“setQuery”我有一个保存在对象中的列列表,所以我浏览列表以使用以下代码创建列:
// 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();
如果要重现此错误,只需键入以下查询:
Select '$' from dual
请注意,“}”字符也会出现同样的错误。
有人可以帮我吗?
答案 0 :(得分: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>
希望这会有所帮助:)