Use of mask for Lookup filtering

I have a lookup field and I want to filter with mask. I’m checking filtering options in LookupField - CUBA Platform. Developer’s Manual but not sure if this allows me to do what I want.

Example:
I have a list of numbers, from 0 to 99999999
I want to do something like we do in SQL with LIKE and % char.
If I write 99%99, I filter all values starting with 99 and finishing with 99, with any combination in the middle. Now, What I need is this same idea but using a dot (.) instead of %.

Is this possible?

No sense to filter anything in a lookupField. I think you mean you want to select a certain item from lookupField entering an expression.using a wildcard to be replaced by some calculated string, i.e. “.” to other string

I made it with this WA

@Inject
LookupField lookupFieldSomething;


@Override
public void ready(){
    lookupFieldSomething.setNewOptionAllowed(true);
    lookupFieldSomething.setNewOptionHandler(new LookupField.NewOptionHandler() {
        @Override
        public void addNewOption(String caption) {
            if (caption.contains(".")) {
                MyObject myObject=searchMyObject(caption); //here you will format caption and get myObject, if exists
                lookupFieldSomething.setValue(myObject);
            }
        }
    });
}

Hello @giuseppe

The task can be easily solved with SuggestionField component: documentation.

In case of using a dot as mask we can consider a query as RegExp and just filter all available items:

// Declaratively install SearchExecutor for our SuggestionField
@Install(to = "suggestionField", subject = "searchExecutor")
private List suggestionFieldSearchExecutor(String query, Map<String, Object> params) {
    // consider a query with dot "." like regexp
    Pattern likeQuery = Pattern.compile(query);

    // "entities" - CollectionContainer
    return entities.getItems()
            .stream()
            .filter(item -> likeQuery.matcher(item.getName()).matches())
            .collect(Collectors.toList());
}

Result:

image

I’ve prepared an example that you can find here: GitHub.

Regards,
Daniil

Sorry for late reply Daniil, At the moment was solved using A. Punzi solution, but I will review your share projects, thanks a lot