Trace: • Using Calculated Values
This is an old revision of the document!
Sometimes, it's useful to add calculated values to your report. To do this, simply use your own implementation of ICalculatedValue.
Here's an example:
Bean bean = new Bean(); bean.put("AMOUNT", BigDecimal.valueOf(11.5)); bean.put("PRICE", BigDecimal.valueOf(15.44)); bean.put("CALCULATED", new ICalculatedValue() { @Override public Object getValue(String pName, INode pNode) { return ((BigDecimal)pNode.get("AMOUNT")).multiply((BigDecimal)pNode.get("PRICE")); } }); BeanNode node = new BeanNode(bean); RtfWorker w = new RtfWorker(); w.loadDocument(getTemplateInputStream("calculatedValues.rtf")); w.fillInData(node); w.saveDocument(new FileOutputStream(getTempOutputFile("result_calculatedValues.rtf")));
If you're using an AbstractDataNode like StorageNode, ListNode or EmptyNode, be sure that you set the calculated value as parameter:
dataNode.setParameter("CALCULATED", new ICalculatedValue() {...});