The following example illustrates a type of expression optimization.
If you want to query a database for information that is not stored in Identity Manager or accessible as a resource account attribute, follow these general steps:
Define a form field that uses a default expression to call the Java class.
Reference the hidden variable.
You will need to write a Java class that has methods that can be called to retrieve information. The example in the following section, Defining a Hidden Form Field, uses the getJobGrade method, which is a custom method. You should locate this custom class in the idm\WEB-INF\classes\com\waveset\custom directory structure. (If these directories do not exist on your system, you must create them.)
Follow these guidelines when writing this class:
If the method performs an expensive operation, such as a database request, you should make the call in the Default expression of a hidden form field. This will cause the value to be stored in the view when the form is first loaded. The value can then be referenced many times without incurring database overhead.
If the method being called has not been declared static, use the new element to instantiate the class first, as shown in the following example.
First, define a hidden form field that uses a default expression to call the Java class by not including any Display class in the field definition:
<Field name=’jobGrade’> <Default> <invoke name=’getJobGrade’ class=’com.waveset.custom.DatabaseAccessor’> <ref>waveset.accountId</ref> </invoke> </Default> </Field> </Derivation>
Default expressions are evaluated only if the view does not contain a value for the attribute jobGrade. Once the default expression has been run, the result is stored in jobGrade, and the expression is not run again.
Select Hidden from the Display Class menu.
The Hidden display class corresponds to the <input type=hidden’/> HTML component. This component supports only single-valued data types because there is no way to reliably serialize and deserialize multi-valued data types.
If you have a List that you want to render it as a string, you must explicitly convert it to a String, as shown in the following example:
<Field name=’testHiddenFieldList’ > <Display class=’Hidden’/ > <Derivation> <invoke name=’toString’> <List> <String>aaaa</String> <String>bbbb</String> </List> </invoke> </Derivation> </Field>
Once you have defined a hidden attribute, you can reference it in other expressions, such as:
<Field name=’secureKey’> <Disable><lt><ref>jobGrade</ref><i>10</i></lt></Disable> ... </Field>
You can use XPRESS defvar variables to hold the results of a computation, but the results are typically not as efficient as using a hidden form field.
XPRESS variables typically persist for only a single iteration over the form fields. As a result, you can use a variable within an Expansion phase but not on a subsequent Derivation phase. If you need a computed value to remain relevant beyond one field iteration, use a hidden form field instead. Hidden field values are stored in the view and will persist until the editing session is either canceled or saved.