Products | Versions |
---|---|
TIBCO EBX | All versions. |
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.
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.