Questo contenuto non è disponibile nella lingua selezionata.

3.7. Data Enumerations


3.7.1. Data Enumerations Drop Down List Configuration

Data enumerations are an optional type of asset that can be configured to provide drop-down lists for the guided editor. They are stored and edited just like any other asset and only apply to the package they are created in.
The contents of an enumeration configuration are the mapping of a fact.field to a list of values. These values are used to populate the drop-down menu. The list can either be literal or use a utility class (which must be added to the classpath) to load the strings. The strings contain either a value to be shown in the drop-down menu or a mapping from the code value (which is what is used in the rule) and a display value, e.g., M=Mini.

Example 3.3. An Example Enumeration Configuration

'Board.type' : [ 'Short', 'Long', 'M=Mini', 'Boogie']
'Person.age' : [ '20', '25', '30', '35' ]
Copy to Clipboard Toggle word wrap

3.7.2. Advanced Enumeration Concepts

Drop-down lists are dependent on field values. With enumerations it is possible to define multiple options based on other field values.
A fact model for insurance policies could have a class called Insurance, consisting of the fields, policyType and coverage. The choices for policyType could be Home or Car. The type of insurance policy will determine the type of coverage that will be available. A home insurance policy could include property or liability. A car insurance policy could include collision or fullCoverage.
The field value policyType determines which options will be presented for coverage, and it is expressed as follows:
 'Insurance.policyType' : ['Home', 'Car']
 'Insurance.coverage[policyType=Home]' : ['property', 'liability']
 'Insurance.coverage[policyType=Car]' : ['collision', 'fullCoverage']
Copy to Clipboard Toggle word wrap

3.7.3. Obtaining Data Lists from External Sources

A list of Strings from an external source can be retrieved and used in an enumeration menu. This is achieved by adding code to the classpath that returns a java.util.List (of strings). Instead of specifying a list of values in the user interface, the code can return the list of strings. (As normal, you can use the "=" sign inside the strings if you want to use a different display value to the rule value.) For example, you could use the following:
'Person.age' : ['20','25', '30', '35']
Copy to Clipboard Toggle word wrap
To:
'Person.age' : (new com.yourco.DataHelper()).getListOfAges()
Copy to Clipboard Toggle word wrap
This assumes you have a class called DataHelper which has a method getListOfAges() which returns a list of strings. The data enumerations are loaded the first time the guided editor is used in a session. To check the enumeration has loaded, go to the package configuration screen. You can "save and validate" the package; this will check it and provide feedback about any errors.

Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat