org.apache.cocoon.forms.formmodel.algorithms
Class RepeatedFormula

java.lang.Object
  extended by org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
      extended by org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
          extended by org.apache.cocoon.forms.formmodel.algorithms.RepeatedFormula
All Implemented Interfaces:
Contextualizable, LogEnabled, CalculatedFieldAlgorithm

public class RepeatedFormula
extends SimpleFormula

An xreporter Expression based algorithm that repeats the formula on a set of fields.

The specified formula will be applied iterating on the specified widgets. The final result will be the result of the last iteration. From inside the formula you can access this two extra variables :

formulaResult
The result of the previous iteration, or the result of the initial result if this is the first iteration.
formulaCurrent
The value of the current trigger widget.

The initial result is evaluated before starting the iteration, and its value is used as a formulaResult for the first iteration.

It's possible to define nearly every cyclic arithmetic operation with this algorithm, for example :

Sum
initial-result="0" formula="formulaResult + formulaCurrent"
Multiplication
initial-result="1" formula="formulaResult * formulaCurrent"

More over, thru the use of advanced xreporter syntax it's possible to quickly implement also complex algorithms:

Note: please take care that xreporter expressions are not that accurate when it comes to decimals. The default divide operator rounds the result, see http://issues.cocoondev.org/browse/XRP-115. Also consider that the available set of functions can be expanded implementing and using new ones. Please see http://outerthought.net/wqm/xreporter/en/expressions.html for an overview of xreportes expressions and IsNullFunction or StringFunction for examples of custom xreporter functions.

Version:
$Id: RepeatedFormula.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
 
Fields inherited from class org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
formula
 
Fields inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
triggers
 
Constructor Summary
RepeatedFormula()
           
 
Method Summary
 Object calculate(Form form, Widget parent, Datatype datatype)
          Performs the actual calculation.
 org.outerj.expression.Expression getInitialResult()
           
 String getRepeatOn()
           
 void setInitialResult(org.outerj.expression.Expression initialResult)
           
 void setRepeatOn(String iterateOn)
           
 
Methods inherited from class org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
getFormula, isSuitableFor, setFormula
 
Methods inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
addTrigger, clearTriggers, contextualize, enableLogging, getContext, getLogger, getTriggerWidgets
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepeatedFormula

public RepeatedFormula()
Method Detail

calculate

public Object calculate(Form form,
                        Widget parent,
                        Datatype datatype)
Description copied from interface: CalculatedFieldAlgorithm
Performs the actual calculation.

Specified by:
calculate in interface CalculatedFieldAlgorithm
Overrides:
calculate in class SimpleFormula
Parameters:
form - The form.
parent - The parent widget of the CalculatedField widget (may be the same as form)
datatype - The target datatype.
Returns:
the calculated value for the CalculatedField.

getInitialResult

public org.outerj.expression.Expression getInitialResult()
Returns:
Returns the initialResult.

setInitialResult

public void setInitialResult(org.outerj.expression.Expression initialResult)
Parameters:
initialResult - The initialResult to set.

getRepeatOn

public String getRepeatOn()
Returns:
Returns the iterateOn.

setRepeatOn

public void setRepeatOn(String iterateOn)
Parameters:
iterateOn - The iterateOn to set.


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.