org.apache.cocoon.forms.formmodel.algorithms
Class RepeatedFormula
java.lang.Object
org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
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:
- Count all items with a price higher than 100 : eval="formulaResult + If(price > 100, 1, 0)"
(read : the result is the previous result plus one if price is over 100, 0 if price is less than 100)
- Obtain a sum of all movements, wether they are positive or negative amount movements :
eval="formulaResult + Abs(amount)"
- Count how many slots are empty in the 10 items box you are using for packaging :
eval="formulaResult + Reminder(items, 10)"
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 $
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RepeatedFormula
public RepeatedFormula()
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.