title: Pass an expression to be evaluated from Java to JasperReports
body: <p>I created a report with three parameters which are:</p>
  
  <ul>
  <li>name (a String with default value "World")</li>
  <li>money (an Double with default value 100)</li>
  <li>formatter (default value new DecimalFormat("#,##0.00"))</li>
  </ul>
  
  <p>I retrieve two records from database:</p>
  
  <ul>
  <li>"\"Hello \" + $P{name}"</li>
  <li>"\"I have \" + $P{formatter}.format($P{money}) + \" dollar\""</li>
  </ul>
  
  <p>I pass these two records to JasperReport and expect to display</p>
  
  <blockquote>
    <p>Hello World<br>
    I have 100.00 dollar</p>
  </blockquote>
  
  <p>However, the expressions are not evaluated and the output becomes this:</p>
  
  <blockquote>
    <p>"Hello " + $P{name}<br>
    "I have " + $P{formatter}.format($P{money}) + " dollar"</p>
  </blockquote>
  
  <p>Since the record number is dynamic, I have to put them in Details band. The tricky part is that each record may have different parameters.</p>
  
  <p>Is there any solution to make this idea works?</p>
  
  <pre><code>Map&lt;String, Object&gt; parameter = new HashMap&lt;String, Object&gt;();
  
  List&lt;String[]&gt; records = new ArrayList&lt;String[]&gt;();
  records.add(new String[] { "\"Hello \" + $P{name}" });
  records.add(new String[] { "\"I have \" + $P{formatter}.format($P{money}) + \" dollar\"" });
  
  String[] columnNames = { "displayText" };
  
  JRDataSource dataSource = new ListOfArrayDataSource(records, columnNames);
  
  JasperPrint jasperPrint = JasperFillManager.fillReport("test.jasper", parameter, dataSource);
  
  JasperViewer viewer = new JasperViewer(jasperPrint);
  viewer.setDefaultCloseOperation(JasperViewer.EXIT_ON_CLOSE);
  viewer.setVisible(true);
  </code></pre>
  
  <p>Report source</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"&gt;
  &lt;property name="ireport.zoom" value="1.4641000000000006"/&gt;
  &lt;property name="ireport.x" value="0"/&gt;
  &lt;property name="ireport.y" value="0"/&gt;
  &lt;parameter name="name" class="java.lang.String" isForPrompting="false"&gt;
      &lt;defaultValueExpression&gt;&lt;![CDATA["World"]]&gt;&lt;/defaultValueExpression&gt;
  &lt;/parameter&gt;
  &lt;parameter name="money" class="java.lang.Double" isForPrompting="false"&gt;
      &lt;defaultValueExpression&gt;&lt;![CDATA[100]]&gt;&lt;/defaultValueExpression&gt;
  &lt;/parameter&gt;
  &lt;parameter name="formatter" class="java.text.DecimalFormat" isForPrompting="false"&gt;
      &lt;defaultValueExpression&gt;&lt;![CDATA[new DecimalFormat("#,##0.00")]]&gt;&lt;/defaultValueExpression&gt;
  &lt;/parameter&gt;
  &lt;field name="displayText" class="java.lang.String"/&gt;
  &lt;detail&gt;
      &lt;band height="20"&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement x="0" y="0" width="555" height="20"/&gt;
              &lt;textElement&gt;
                  &lt;font fontName="Arial Unicode MS"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression class="java.lang.String"&gt;&lt;![CDATA[$F{displayText}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
      &lt;/band&gt;
  &lt;/detail&gt;
  </code></pre>
  
  <p></p>