Class ValueOptions<I>

java.lang.Object
com.vaadin.flow.component.ai.form.ValueOptions<I>
Type Parameters:
I - the per-label item type the controller's converter must produce. For a single-value field I is the field's value type; for a multi-select field I is the per-element type. The controller's valueOptions(...) overload set enforces at compile time that a converter is supplied for every I other than String

public final class ValueOptions<I> extends Object
Per-field options registration passed to controller.valueOptions(...). Carries the field together with either a fixed label list or a query callback. The label-to-value converter is supplied separately to the controller at registration time, not on this object — see valueOptions(config, toValue).

Two forField factories cover all field shapes:

  • forField(HasValue) — single-value fields. The type parameter V of the field flows through.
  • forField(MultiSelect) — multi-select fields. Picked by the compiler whenever the reference is statically typed as MultiSelect. The per-element type flows through; the controller aggregates resolved per-label items into a LinkedHashSet before HasValue.setValue(V).
Exactly one of options(Collection) (fixed labels) and options(BiFunction) (queryable labels) must be set; calling one clears the other so the last setter wins.
Author:
Vaadin Ltd
  • Method Details

    • forField

      public static <V> ValueOptions<V> forField(com.vaadin.flow.component.HasValue<?,V> field)
      Starts a single-value options registration. The field's value type V flows through; for a V other than String, the controller's two-argument FormAIController.valueOptions(ValueOptions, Function) overload must be used to supply a converter — that is a compile-time requirement, not a runtime check.
      Type Parameters:
      V - the field's value type
      Parameters:
      field - the single-value field whose options the LLM may pick from, not null
      Returns:
      a fresh registration ready to receive options(...)
    • forField

      public static <T, C extends com.vaadin.flow.component.Component> ValueOptions<T> forField(com.vaadin.flow.data.selection.MultiSelect<C,T> field)
      Starts a multi-select options registration. Picked by the compiler over forField(HasValue) whenever the reference is statically typed as MultiSelect. The per-element type flows through; for any type other than String, the controller's two-argument FormAIController.valueOptions(ValueOptions, Function) overload must be used. The controller aggregates resolved per-label items into a LinkedHashSet before HasValue.setValue(V).
      Type Parameters:
      T - the per-element type
      C - the field's source-component type
      Parameters:
      field - the multi-select field whose options the LLM may pick from, not null
      Returns:
      a fresh registration ready to receive options(...)
    • options

      public ValueOptions<I> options(Collection<String> options)
      Sets a fixed label list. A defensive copy is taken so later mutations of the caller's collection have no effect. Mutually exclusive with options(BiFunction) — calling either clears the other.
      Parameters:
      options - the labels the LLM may pick from, not null and not empty
      Returns:
      this registration, for chaining
      Throws:
      IllegalArgumentException - if options is empty — registering an empty fixed list leaves the field un-fillable and is always a developer mistake
    • options

      public ValueOptions<I> options(BiFunction<String,Integer,List<String>> query)
      Sets a queryable label callback the LLM drives via query_field_options. Mutually exclusive with options(Collection) — calling either clears the other.
      Parameters:
      query - the filter callback returning labels for the LLM, not null
      Returns:
      this registration, for chaining