How to forbid multiple selection of the same value on multi-valuated enumeration

How to forbid multiple selection of the same value on multi-valuated enumeration

book

Article ID: KB0073977

calendar_today

Updated On:

Products Versions
TIBCO EBX All versions.

Description

On multi-valued enumeration fields, it is possible to select the same value several times on different occurrences of the field.

The purpose of this article is to describe how to implement a TableRefFilter constraint allowing to forbid multiple seletion of the same value.

Issue/Introduction

How to forbid multiple selection of the same value on multi-valuated enumeration

Resolution

For this example, we will use a simple data model with 2 tables "table1" and "table2" with a multi-valued foreign key in "table1".
We want to forbid multiple selection on the same "table2" record for a "table1" record.

User-added image

Implement a TableRefFilter as the following:

TableRefFilter
package com.orchestranetworks.support.module;
 
import java.util.List;
import java.util.Locale;
 
import com.onwbp.adaptation.Adaptation;
import com.onwbp.adaptation.PrimaryKey;
import com.orchestranetworks.instance.ValueContext;
import com.orchestranetworks.schema.InvalidSchemaException;
import com.orchestranetworks.schema.Path;
import com.orchestranetworks.schema.TableRefFilter;
import com.orchestranetworks.schema.TableRefFilterContext;
 
public class UnicityTableRefFilter implements TableRefFilter{
 
    @Override
    public boolean accept(Adaptation aRecord, ValueContext currentContext) {
         
        // Retrieve the id of the record to filter in table 2
        PrimaryKey id = aRecord.getOccurrencePrimaryKey();
         
        //Retrieve the value of the fkT2 list in the current form
        @SuppressWarnings("unchecked")
        List<String> fk2InCurrentForm = (List<String>) currentContext.getValue(Path.parse("../fkT2"));
         
        //This is the value currently selected in the field (null when the user click on [+] and valued while submitting the form.
        String itemValue = (String) currentContext.getValue();
         
        if( fk2InCurrentForm != null && fk2InCurrentForm.contains(id.format()) && itemValue == null )
            return false;
         
        return true;
    }
 
    @Override
    public void setup(TableRefFilterContext context) {
        // TODO Auto-generated method stub
    }
 
    @Override
    public String toUserDocumentation(Locale userLocale, ValueContext aContext)
            throws InvalidSchemaException {
        // TODO Auto-generated method stub
        return null;
    }
 
}


After positionning the TableRefFilter on the foreign key field, you cannot select several times the same record anymore.
The class and the data model are attached.

Additional Information

https://docs.tibco.com/pub/ebx/5.9.8/doc/html/en/Java_API/com/orchestranetworks/schema/TableRefFilter.html

Attachments

How to forbid multiple selection of the same value on multi-valuated enumeration get_app
How to forbid multiple selection of the same value on multi-valuated enumeration get_app