Adding Custom Business Logic using Expression Language

On the field properties page, a Custom option is available for most properties by clicking This image shows the custom option or selecting Custom from the properties drop-down list.

The custom option enables you to add Expression Language (EL) code to add custom business logic to the page panel.

For example, rather than a field always being read only or always being mandatory (properties = YES) , expression language can be coded to perform a test and the field properties conditionally set to YES (true) or NO (false).

Expression language can also be used to conditionally set the color properties of a field.

Expression language can also be used to perform specific actions such as displaying a message to a user or setting the value of another field if an expression evaluates as true.

Note:

When the properties of a field have been customized, a reset link appears next to the field property. The reset link helps identify if a field has been customized and you can click this link to remove the customization.

Example 1-1 Example 1

Color Properties — Change the Background color of the member type field based on the membership type = 'OR'

Click This image shows the custom option for the Background color property for the membership type field and add the following EL expression:
#{bindings.MembershipType.inputValue == 'OR' ? '#ffff00' : '#ffffff' } 
  • If the statement evaluates as true, then set the background color of the field changes to Hex Color #ffff00 (yellow).

  • If the statement evaluates as false (membership type is not = OR), then set the background color to white.

Example 1-2 Example 2

Color Properties — Change the background color of the member type field based on the membership type = 'OR'

Click This image shows the custom option for the Background color property for the membership type field and add the following EL expression:
#{bindings.MembershipType.inputValue == 'OR' ? '#0493f2'  : '#ffffff' } 
  • If the statement evaluates as true, then set background color of the field changes to Hex Color #0493f2' (blue).

  • If the statement evaluates as false (membership type is not = OR), then set the background color to white.

Example 1-3 Example 3

Required Property — Set the Visa Expiry Date field as Required = YES if the Visa Number field has a value (is not null).

Click This image shows the custom option for the Required property for the Visa Expiry Date field and add the following EL expression:
#{bindings.VisaNumber.inputValue== null ? false : true}
  • If the statement evaluates as true (NULL), then set REQUIRED = NO (false).

  • If the statement evaluates as false (not NULL), then set REQUIRED = YES (true).

Example 1-4 Example 4

Required Property — Set the state field as Required = YES if the country code field has a value of either CA, USA, or AU

Click This image shows the custom option for the Required property for the State field and add the following EL expression:
#{bindings.CountryName.inputValue=='CA' ? true : bindings.CountryName.inputValue=='USA' ? true : bindings.CountryName.inputValue=='AU'  ? true
  • If the statement evaluates as true then set REQUIRED = YES (true).

  • If the statement evaluates as false then set REQUIRED = NO (false).

Using EL to perform specific actions

Expression Language can also be used to program specific actions to occur based on a condition evaluating as true or false.

Custom actions are programmed from the Advanced tab on the field properties page to define an IF THEN ELSE condition.

These expressions can be used to test a value in a field and then set a value in another field, display a message to a user, or both.

The following actions can be selected from the Action drop-down list:
  • No Action

  • Show Message

  • Update Field

  • Show Message and Update Field

For Show Message actions, you can select a message type to display a suitable icon in the message text. The following options are available:
  • Info

  • Error

  • Warning

  • None

Select Add Condition to code EL for a custom action.
  • Under the If (condition), select Custom to enter an EL expression via </>.

  • Under Then (True), select the required action.

  • Under Else (False), select the required action.

Example 1-5 Example 5 — Show a message to the user when a field equals a certain value

Stay Details — If the room type code = PM and the Print Rate = Y, then show a message to the user.
#{bindings.RoomType.inputValue == 'PM' ? true : #bindings.PrintRate.inputValue == 'Y' ? true : false}

Figure 1-1 Customize screen — Advanced tab


This figure shows the Advanced tab on the Customize screen and an If condition that results in a message appearing to the user.

For more information on EL expressions, refer to the following:

https://docs.oracle.com/javaee/7/tutorial/jsf-el.htm

https://docs.oracle.com/javaee/6/tutorial/doc/gjddd.html