How to run if-else in jexl? -


here 3 int parameters:a,b,c. , 1 string parameter:d. here code in java:

if (a>1) return c+d; if (b<2) return c-d; if (d.equals("123") return c*d; return c+1; 

how turn above code jexl? tried many times, including using var. return null.

probably use jexl expression instead of script. can use ternary conditional in expression. if-else, return, for, while should used in script:

jexlengine jexl = new jexlbuilder().create(); jexlscript script = jexl.createscript(scripttext); result = script.execute(context); 

see http://commons.apache.org/proper/commons-jexl/reference/syntax.html

from javadoc:

an expression different script - reference single expression, not multiple statements. implies 'if','for','while','var' , blocks '{'... '}'are not allowed in expressions.

a script valid jexl syntax executed given set of jexlcontext variables. script group of statements, separated semicolons. statements can blocks (curly braces containing code), control statements such if , while expressions , assignment statements.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -