0

I am using MVEL to execute an expression which is a mathematical formula. The expression is in this format

10 * availableSI

I have a DataObject which has availableSI as a parameter which has its getter and setter.

When I say MVEL.eval(expression,DataObject), it executes the expression by finding the value of availableSI from the dataobject and returns the final result

However, i need the expression which would have the runtime value of availableSI (if avaiableSI is 1000), 10 * 1000

Need help.

Harshul Pandav
  • 1,016
  • 11
  • 23

1 Answers1

0

Call your function in constructor to retrieve dynamic value.

public class Rules extends SimpleVariableResolverFactory
{    
    public Rules()
    {
            super(new HashMap());
            String newValue = callToYourFunction();
            super.createVariable("availableSI" , newValue);
    } 

    public static void main(String[] argv)
    {
          Rules arf = new Rules();
          String expression="avaiableSI * 10"; //Your expression
          Serializable compiledExpression = MVEL
                            .compileExpression(expression);

          System.out.println(expression + " == "
                            + MVEL.executeExpression(compiledExpression, arf)
    }
}
Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
Yogendra Joshi
  • 228
  • 1
  • 8