EL Functions

Since using EL expressions is a very handy feature for all kinds of purposes, they are supported by Calyxo in many places. As described in the Functions Reference section, Calyxo comes with three groups of predefined functions: Standard Functions (for string manipulation), Module Functions and Type Functions (for type conversions).

To be able to use additional functions in your EL expressions, you usually have to perform to steps:

  1. Write a public Java class containing a public static method for every function you intend to use. The only restriction one has to obey is, that no multiple method names are used. That means that instead of implementing two methods long max(long, long) and double max(double, double) you have to choose different method names like maxLong and maxDouble, or similarly long min(long, long) and long min(long, long, long) might be renamed to long min2(long, long) and long min3(long, long, long).
  2. Register your Java class in that configuration file, where it shall be used (registered functions are not imported!). This is done by using the <functions> tag as described in the Functions Reference section.

Of course, the first step may be skipped if a suitable Java class does already exist, either written by yourself or taken from a third party library. In other cases, a class providing all required functions does exist, but is not suitable as a functions class because of multiple method names (examples are the classes java.lang.Math, java.util.Arrays and java.util.Collections, which supply a lot of useful methods for number and collection manipulations). Here it is sufficient to write a new class which delegates all functionality to the desired class.

Example

The following code illustrates the sceleton of a class providing some useful functions for date calculations.

package my.functions;

public class DateFunctions {
  public static Date today() {
    // calculate the current date
    return date;
  }
  public static boolean isFuture(Date date) {
    // test if date is larger than today
    return result;
  }
  public static boolean isPast(Date date) {
    // test if date is smaller than today
    return result;
  }
  public static long daysBetween(Date begin, Date end) {
    // calculate difference between the two dates
    return days;
  }
}

The class is registered in your configuration file by writing

<base:functions prefix="date" class="my.functions.DateFunctions"/>

Now the above functions may be accessed like follows: ${date:daysBetween(date:today(), departureDate)}.