How to show specific Enum values

Hello team,

is there a way to show specific Enum values, for example if i have Enum called party with 3 values “Employee”, “Company” and “Other”, and in an entity called payments i have an attribute called “Paying Party”, i want the dropdown list for this attribute to show only “Employee” and “Company”, but in other attribute called “Receiving Party” i want to show all the values. is this possible using the same enum for both attributes?


this is totally possible but it requires a little bit of custom programming.

Here’s the example: GitHub - mariodavid/cuba-example-filter-enum-values: CUBA example that shows how to only allow a subset of enum values


CUBA example that shows how to only allow a subset of enum values

In order to filter for particular enum values, the method setOptionsList can be used from LookupField to make this happen.

payments-edit screen

<fieldGroup id="fieldGroup"
    <column width="250px">
        <field property="payingParty" custom="true"/>
        <field property="receivingParty" custom="true"/>

PaymentsEdit controller

import static de.diedavids.cuba.cefev.entity.Party.*

class PaymentsEdit extends AbstractEditor<Payments> {

    @Inject FieldGroup fieldGroup
    @Inject ComponentsFactory componentsFactory
    @Inject Datasource<Payments> paymentsDs

    void init(Map<String, Object> params) {
        initPartyAttribute("payingParty", [EMPLOYEE, COMPANY])
        initPartyAttribute("receivingParty", [EMPLOYEE, COMPANY, OTHER])

    protected void initPartyAttribute(String attribute, List<Party> partyOptions) {
        FieldGroup.FieldConfig payingPartyFieldConfig = fieldGroup.getField(attribute)
        LookupField lookupComponent = componentsFactory.createComponent(LookupField.NAME) as LookupField
        lookupComponent.setDatasource(paymentsDs, attribute)
        lookupComponent.optionsList = partyOptions
        payingPartyFieldConfig.component = lookupComponent


Resulting application