= Choices

: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:


A drop-down list of _choices_ for a property can be specified using a supporting method matched by prefix, returned datatype and name:

[source,java]
----
import lombok.Getter;
import lombok.Setter;

public class Customer {

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

    public List<String> choicesPaymentMethod() {            // <.>
        return Arrays.asList("Visa", "Mastercard", "Amex");
    }

    // ...
}
----
<.> If required; properties are by default disabled globally.
<.> Note the "choices" prefix and the suffix matching up with the getter.
The method must return a collection of the same type as the property.

For an action, the _choices_ for the N-th parameter can be specified by a prefix, the parameter number, with the suffix being the name of the action:

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

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

    public List<String> choices1Invoice() {         // <.>
        return this.getPaymentMethods();
    }

    // ...
}
----
<.> "choices" prefix, N-th param, suffix matches up with the action's name.
Returns a collection of the same type as the parameter.
