List distinct values of another table field in a combo box.

List distinct values of another table field in a combo box.

book

Article ID: KB0073981

calendar_today

Updated On:

Products Versions
TIBCO EBX All supported versions.

Description

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.

Issue/Introduction

List distinct values of another table field in a combo box.

Resolution

Implementation

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 dataset
AdaptationTable table1 = dataset.getTable(Path.parse("/root/table1")); //retrieve table1
 
RequestSortCriteria criteria = new RequestSortCriteria();
criteria.add(Path.parse("./val"));
 
RequestResult result = table1.createRequestResult(null, criteria); // create a request on table1 and sort it by 'val' field
 
Adaptation currentRecord = result.nextAdaptation();
String currentValue = null;
String previousValue = null;
 
while (currentRecord != null){ // go through the request result
 
currentValue = currentRecord.getString(Path.parse("./val")); // get the current value
 
if (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;
}

Results

Content of "table1" Enumeration field in "table2"
User-added image User-added image

Additional Information

https://docs.tibco.com/pub/ebx/5.9.12/doc/html/Java_API/com/orchestranetworks/schema/ConstraintEnumeration.html