= AutoComplete

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
:page-partial:




The _autocomplete_ is similar to _choices_, but accepts a string parameter, to search for matching results.
A property for example might have:

[source,java]
----
public class Order {

    @Property(editing = Editing.ENABLED)                        // <.>
    @Getter @Setter
    private Product product;

    public List<Product> autoCompleteProduct(                   // <.>
                            @MinLength(2) String search) {      // <.>
        return productRepository.findByReferenceOrName(search);
    }

    // ...
}
----
<.> If required; properties are by default disabled globally.
<.> "autoComplete" prefix, suffix matches property name. +
Returns a collection of the property's type.
<.> The `@MinLength(...)` annotation indicates the minimum number of characters that must be entered before a search is initiated.

Actions are very similar.
Here the supporting "autoComplete" method is matched by number:

[source,java]
----
public class Customer {

    public Order invoice(
            ShoppingCart cart,
            String paymentMethod,
            DiscountVoucher voucher,
            LocalDate shipBy) {
        ...
        return this;
    }

    public List<DiscountVoucher> autoComplete2Invoice(      // <.>
                    @MinLength(2) String voucherCode) {
        return discountVoucherRepository.findByVoucherCode(this, voucherCode);
    }

    // ...
}
----
<.> "autoComplete" prefix, N-th param, suffix matches action name. +
Returns a collection of the parameters type.

An _autoComplete_ method can be used in conjunction with a _default_ method, but it doesn't make sense to provide both an _autoComplete_ and a _choices_ method.

