Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Definition

An expression is a lightweight function that does not maintain a state. Expressions are used

Excerpt

Uses script code to calculate values within a single row of

a report. Expressions can use

a

dataRow to access other fields, expressions or functions within the current row in the

report.

Examples

Code Block
xml
xml
<expression class="org.jfree.report.modules.misc.beanshell.BSHExpression" name="totalPrice">
  <properties>
    <property name="expression">
     Object getValue() { 
       if (dataRow == null) { 
         return null; 
       }      
       Number OrderCount = (Number) dataRow.get(&quot;QUANTITYORDERED&quot;); 
       Number SalePrice = (Number) dataRow.get (&quot;PRICEEACH&quot;); 
       if (OrderCount == null || SalePrice == null) { 
         return null;
       }
       float totalPrice = OrderCount.floatValue() * SalePrice.floatValue();      
       return new Float (totalPrice); 
     }
    </property>
   </properties>
</expression>

<expression class="org.jfree.report.modules.misc.beanshell.BSHExpression" name="isVarianceNegative"> 
<properties>
   <property name="expression">
    Object getValue() { 
      Object value = dataRow.get(&quot;VARIANCE&quot;);  
      if (value instanceof Number == false) {  
        return Boolean.FALSE;
      }
      Number number = (Number) value;
      if (number.doubleValue() < 0) {
        return Boolean.TRUE;
      }
      return Boolean.FALSE;
    }
    </property>
 </properties>
</expression>