Questions tagged [jexl]

JEXL is a library intended to facilitate the implementation of dynamic and scripting features in applications and frameworks written in Java.

JEXL is a library intended to facilitate the implementation of dynamic and scripting features in applications and frameworks written in Java.

From the official documentation:

JEXL implements an Expression Language based on some extensions to the JSTL Expression Language supporting most of the constructs seen in shell-script or ECMAScript. Its goal is to expose scripting features usable by technical operatives or consultants working with enterprise platforms.

The library exposes a small footprint API - the core features fit in 3 classes and 10 methods - that can be used in various conditions:

  • Scripting features:
    • Your application lets (advanced) users evaluate or define some simple expressions like computation formulas.
  • Module or component configuration:
    • Your application has configuration files (eventually generated by a design module) consumed by the end-user module that would benefit from variables and expressions.
    • When it would be convenient to use IOC but overall complexity doesn't require (or can't depend upon) a full-blown library (Spring, Guice...).
  • Loose-coupling of interfaces and implementations or duck-typing:
    • You have optional classes that your code cant consider as compilation dependencies.
    • You have to integrate and call "legacy" code or use components that you don't want to strongly depend upon.
  • Simple template capabilities:
    • Your application has basic template requirements and JSPs or Velocity would be overkill or too inconvenient to deploy.

JEXL name stands for Java EXpression Language, a simple expression language originally inspired by Apache Velocity and the Expression Language defined in the JavaServer Pages Standard Tag Library version 1.1 (JSTL) and JavaServer Pages version 2.0 (JSP). JEXL 2.0 added features inspired by Unified EL. The syntax is now close to a mix of ECMAScript and "shell-script" making it easy to master by technical operatives or consultants. The objects exposed and their behavior obviously need to be documented though...

The API and the expression language exploit Java-beans naming patterns through introspection to expose property getters and setters. It also considers public class fields as properties and allows to invoke any accessible method.

JEXL attempts to bring some of the lessons learned by the Velocity community about expression languages in templating to a wider audience. Commons Jelly needed Velocity-ish method access, it just had to have it.

It must be noted that JEXL is not a compatible implementation of EL as defined in JSTL 1.1 (JSR-052) or JSP 2.0 (JSR-152). For a compatible implementation of these specifications, see the Commons EL project.

79 questions
2
votes
2 answers

How to run if-else in jexl?

Here are 3 INT parameters:a,b,c. And 1 String parameter:d. Here is 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 to turn above code to Jexl? I tried many times, including using var. But it…
zchen
  • 109
  • 2
  • 7
2
votes
1 answer

Java Apache JEXL boolean expressions issue

I'm developing in Java a system to check the occurrence of a combination of keywords in a text. For example, I have the following expression to check: ( yellow || red ) && sofa . I divided the job into two steps. The first one is to detect…
Brianzaska
  • 51
  • 7
2
votes
2 answers

JEXL evaluate returns int

JEXL evaluate returns int instead of float: JexlEngine jexl = new JexlEngine(); Expression e = jexl.createExpression("7/2"); Float result = (Float)e.evaluate(null); I receive this error: java.lang.ClassCastException: java.lang.Integer cannot be…
Andrew
  • 3,545
  • 4
  • 31
  • 37
2
votes
1 answer

Special Characters in Scriptella, jexl

I want to extract a text field from a database and insert it into some other database. So while extracting I used the REPLACE(message_text,'\'', '"') while selecting the test. I gave me an error. I changed that from my select statement and did it…
Kranthi
  • 23
  • 4
1
vote
2 answers

Long to Double in Jexl

I use Jexl lib from apache and have some problems with using the evaluate() method of Expression class. Here is the code of NelderMead class: import org.apache.commons.jexl2.*; public class NelderMead { // контсанты private static int …
Dmitry Belaventsev
  • 6,347
  • 12
  • 52
  • 75
1
vote
2 answers

Can't create JexlEngine object

I write the following class: import org.apache.commons.jexl2.*; public class NelderMead { // контсанты private static int M = 3; private static double E = 0.005; private static double A = 1.000; private static double …
Dmitry Belaventsev
  • 6,347
  • 12
  • 52
  • 75
1
vote
1 answer

How to set Jexcel name in Spring mvc?

I'm following with mkyong Jexcel with Spring tutorial and everything looks fine.it can create excel file and write sheet except one thing is I can't change my excel file name? It will display file name same as my link to controller. Here is…
Vtanathip
  • 109
  • 2
  • 11
1
vote
1 answer

validate a Jexl script under "compile" terms?

See this example: public class JexlStuff { private static final JexlEngine jexl = new JexlBuilder().cache(512).strict(true).silent(false) .safe(true).create(); public static void main(String[] args) { JexlScript script…
George Z.
  • 6,643
  • 4
  • 27
  • 47
1
vote
2 answers

How to disable JEXL assignments?

I have an application that allows users to enter JEXL expressions. They are used as search filters. A common mistake users do is to write something like "A=5" and expect the filter to be true if and only if the variable A contains the value 5. Yes,…
Queeg
  • 7,748
  • 1
  • 16
  • 42
1
vote
0 answers

What are the differences between the variations of JEXL?

Does anyone know the best place where I can go to see the differences between the variations of JEXL? I've noted the following so far. Expression This only allows for a single command to be executed and the result from that is returned. If you try…
Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
1
vote
1 answer

How to convert type for JEXL expressions?

I use JEXL expressions so users can specify expressions at runtime and my application will process them accordingly. Now as a special case users want to compare floating point values, however in the JEXL context these variables contain strings like…
Queeg
  • 7,748
  • 1
  • 16
  • 42
1
vote
1 answer

Using JEXL in Cloud Data Fusion

I'm using wrangler component of cloud data fusion. I want to set new column with current date. set-column :current_date new("java.time.LocalDateTime.now()"); Throws "The preview of the pipeline "test" has failed. Please check the logs for more…
Arty
  • 139
  • 9
1
vote
1 answer

Jexl perform dynamic string transformation

I am building an evaluator which underneath uses JEXL. I know how to introduce the workspaces in Jexl, but that only allows a class definition, I need to define a method definition. In the following example, for getting access to log function of…
1
vote
1 answer

JexlEngine constructor not working? (cannot be applied to given types)

I am trying to initialize an JexlEngine object, but the constructor does not let me do so (although the documentation states it should). Here's the documentation for the JexlEngine class (in…
Bg Zape
  • 40
  • 6
1
vote
1 answer

JMeter _jexl3 function with multiple conditions

I'm a newbie in Jmeter 4.0. I want a single IF controller in my Thread group executing True or False relation using Boolean ie; 0 and 1. Currently i'm using two IF controllers with the expressions ${__jexl3(${VAR}==1)} and ${__jexl3(${VAR}==0)} and…
Aadhi
  • 153
  • 7