$IF Handler
The handler allows to perform different actions depending on whether a user provided condition evaluates to
true or
false . It can be used in the two forms which are shortly described below
- $IF{[condition], [action]}
The condition is a piece of text which should evaluated to true / false or 1 / 0 value. In case it evaluates to true / 1 value the action block is executed. Both condition and action can contain Groovy expression, parameters, data fields, etc.
- $IF{[condition], [action], [actionWhenFalse]}
This form extends the form described above by executing the actionWhenFalse in case the condition evaluates to false / 0.
Examples
- CustomerDetails - shows details of the customer specified by the customerId parameter.
The data set customer which is used in this example is defined as follows:
select
first_name, last_name, email, active,
address, address2, district, city, country,
postal_code, phone, count(rental.rental_id) num_rentals
from
customer, address, city, country, rental
where
rental.customer_id=customer.customer_id
and
customer.customer_id=$P{customerId}
and
customer.address_id=address.address_id
and
city.city_id=address.address_id
and
city.country_id=country.country_id
group by
customer.customer_id
The document is using two IF statements, (screenshots below)
This statement causes the highlighted
Not Active text to appear in case the customer is no longer active.
This statement makes the text
This customer has no rentals appear in case there are no rentals assigned to this customer in the database, otherwise the text
Number of rentals will appear.
The sample result document for a non-active customer is shown below: