| Products | Versions |
|---|---|
| TIBCO EBX | All supported versions. |
In this article we will give an example of constraint that will list distinct values of another table field in a dropdown.
To achieve this we implemented a programmatic enumeration ConstraintEnumeration.
In our example we want to display distinct values of field "val" of table 1 in an "enum" field of table 2.
getValues method implementation:
public List<String> getValues(ValueContext context) throws InvalidSchemaException {List<String> list = new ArrayList<String>();Adaptation dataset = context.getAdaptationInstance(); // retrieve datasetAdaptationTable table1 = dataset.getTable(Path.parse("/root/table1")); //retrieve table1RequestSortCriteria criteria = new RequestSortCriteria();criteria.add(Path.parse("./val"));RequestResult result = table1.createRequestResult(null, criteria); // create a request on table1 and sort it by 'val' fieldAdaptation currentRecord = result.nextAdaptation();String currentValue = null;String previousValue = null;while (currentRecord != null){ // go through the request resultcurrentValue = currentRecord.getString(Path.parse("./val")); // get the current valueif (currentValue != previousValue){list.add(currentValue); // we add it to the list if it is different from the previous value}previousValue = currentValue;currentRecord = result.nextAdaptation();}return list;} |
| Content of "table1" | Enumeration field in "table2" |
![]() | ![]() |