Using Calculated Values

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() 
	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.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() {...});
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information