Binding Expressions

Sometimes the restrictions and custom SQL queries are not static but should change depending on the current user, current database server, or current date or time. The DataSource can evaluate binding expressions in the restriction values and in the SQL queries.

For example, the expression "SELECT count(wr_id) FROM wr WHERE requestor = ${user.name}" can be evaluated to " SELECT count(wr_id) FROM wr WHERE requestor = 'AFM'" .

You can use binding expressions in:

  • Parsed restriction field value:
    ds.addRestriction(Restrictions.eq("em", "email", "${user.email}"));
  • SQL restriction text:
    ds.addRestriction(Restrictions.sql("status IN (${parameters['statuses']})"));
  • SQL query text:
    ds.addQuery("SELECT COUNT(*) AS late_projects FROM project " + "WHERE date_est_completion < ${sql.currentDate}", DataSource.DIALECT_GENERIC);

The DataSource will evaluate binding expressions when you call one of the data access methods described in the next chapter. Binding expressions can reference values of the following Web Central objects: user, parameters, SQL, and panel.