Auto-complete

The autoCompleteRepository() element nominates a single method on a domain service as the fallback means for looking up instances of the domain object using a simple string.

For example, this might search for a customer by their name or number. Or it could search for a country based on its ISO-3 code or user-friendly name.

If you require additional control - for example restricting the returned results based on the object being interacted with - then use the autoComplete…​() supporting method instead.

For example:

@DomainObject(
    autoCompleteRepository=CustomerRepository.class
)
public class Customer {
   ....
}

where:

@DomainService
public class CustomerRepository {
    List<Customer> autoComplete(String search);  (1)
    ...
}
1 is assumed to be called "autoComplete", and accepts a single string

(As noted above) the method invoked on the repository is assumed to be called "autoComplete". The optional autoCompleteMethod() element allows the name of this method to be overridden.

For example:

@DomainObject(
    autoCompleteRepository=Customers.class,
    autoCompleteAction="findByName"
)
public class Customer {
   ....
}

where in this case findByName might be an existing action already defined:

@DomainService
public class Customers {

    @Action(semantics=SemanticsOf.SAFE)
    public List<Customer> findByName(
        @MinLength(3)                       (1)
        @ParameterLayout(named="name")
        String name);
    ...
}
1 end-user must enter minimum number of characters to trigger the query
The autocomplete "action" can also be a regular method, annotated using @Programmatic. That is, it does not need to be part of the metamodel:

+

@DomainService
public class Customers {
    @Programmatic
    public List<Customer> findByName(
        @MinLength(3)
        String name);
    ...
}