Class ValueOptions<V>
- Type Parameters:
V- the item type — the field's value type for single-value fields, the per-element type for multi-select fields
ComboBox<Project> registration passes
Project items, not pre-rendered strings. Pass the configured
registration to controller.fieldValueOptions(...) to apply it.
The item set is either fixed (options(Collection)) or supplied on
demand by a callback (options(BiFunction)); exactly one must be set,
with the last call winning. Each item is rendered to an LLM-facing label
through this chain: the explicit
itemLabelGenerator(ItemLabelGenerator) if set, otherwise the field's
own setItemLabelGenerator(...) (read reflectively), otherwise
String.valueOf(Object). The controller resolves a chosen label back
to an item by applying the same chain to each registered item and returning
the first whose label matches, so the field's UI label generator drives the
AI labels automatically.
- Since:
- 25.2
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> ValueOptions<V> forField(com.vaadin.flow.component.HasValue<?, V> field) Starts an options registration for a single-value field.static <T,C extends com.vaadin.flow.component.Component>
ValueOptions<T> forField(com.vaadin.flow.data.selection.MultiSelect<C, T> field) Starts an options registration for a multi-select field.itemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<V> generator) Sets the item-to-label function the controller uses to derive the LLM-facing label for each item.options(Collection<V> options) Sets a fixed item list.Sets a callback the controller invokes whenever the LLM needs to see the field's options.
-
Method Details
-
forField
Starts an options registration for a single-value field. The field's value typeVflows through unchanged.- Type Parameters:
V- the field's value type- Parameters:
field- the single-value field whose options the LLM may pick from, notnull- Returns:
- a fresh registration ready to receive
options(Collection)oroptions(BiFunction)
-
forField
public static <T,C extends com.vaadin.flow.component.Component> ValueOptions<T> forField(com.vaadin.flow.data.selection.MultiSelect<C, T> field) Starts an options registration for a multi-select field. Picked by the compiler overforField(HasValue)whenever the reference is statically typed asMultiSelect. The per-element typeTflows through unchanged; resolved items are aggregated into aLinkedHashSetbeforeHasValue.setValue(V).- Type Parameters:
T- the per-element typeC- the field's source-component type- Parameters:
field- the multi-select field whose options the LLM may pick from, notnull- Returns:
- a fresh registration ready to receive
options(Collection)oroptions(BiFunction)
-
options
Sets a fixed item list. A defensive copy is taken so later mutations of the caller's collection have no effect. Use this when the option set is known up front and small enough to enumerate; for large or dynamic sets useoptions(BiFunction)instead. Mutually exclusive withoptions(BiFunction)— calling either clears the other.- Parameters:
options- the items the LLM may pick from, notnulland not empty; each item is rendered to an LLM-facing label through the chain documented on the class JavaDoc- Returns:
- this registration, for chaining
- Throws:
IllegalArgumentException- ifoptionsis empty — registering an empty fixed list leaves the field un-fillable and is always a developer mistake
-
options
Sets a callback the controller invokes whenever the LLM needs to see the field's options. Use this when the option set is too large or too dynamic for a fixed list viaoptions(Collection)— for example options that come from a database query or a remote service. The callback returns items the LLM may pick from; each item is rendered to an LLM-facing label through the chain documented on the class JavaDoc. Mutually exclusive withoptions(Collection)— calling either clears the other.- Parameters:
query- invoked with two arguments: a filter string the LLM picked, and a positive limit on how many items to return. Returns the matching items in display order, notnull(an empty list signals "no matches" to the LLM)- Returns:
- this registration, for chaining
-
itemLabelGenerator
public ValueOptions<V> itemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<V> generator) Sets the item-to-label function the controller uses to derive the LLM-facing label for each item. Optional — when unset, the controller falls back to the field's owngetItemLabelGenerator()(read reflectively), then toString.valueOf(Object)as a last resort. Set this when the field's UI label generator is absent or when the LLM needs a different label from the UI (for example a code rather than a display name). Calling this multiple times overwrites the previous value.Two items rendering to the same label are resolvable but ambiguous: resolution picks the first matching item in registration order, and the controller logs a warning at registration when this happens. Emit unique labels per item if disambiguation matters.
- Parameters:
generator- the per-item label generator, notnull- Returns:
- this registration, for chaining
- Since:
- 25.3
-