Files
spring-shell/spring-shell-docs/modules/ROOT/pages/using-shell-components-ui-singleselect.adoc
2023-08-03 15:25:32 -05:00

43 lines
1.3 KiB
Plaintext

[[using-shell-components-ui-singleselect]]
= Single Select
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
A single select component asks a user to choose one item from a list. It is similar to a simple
dropbox implementation. The following listing shows an example:
[source, java, indent=0]
----
include::{snippets}/UiComponentSnippets.java[tag=snippet6]
----
The following image shows typical output for a single select component:
image::component-single-select-1.svg[text input]
The context object is `SingleItemSelectorContext`. The following table describes its context variables:
[[singleitemselectorcontext-template-variables]]
.SingleItemSelectorContext Template Variables
|===
|Key |Description
|`value`
|The returned value when the component exists.
|`rows`
|The visible items, where rows contains maps of name and selected items.
|`model`
|The parent context variables (see xref:using-shell-components-ui-render.adoc#selectorcomponentcontext-template-variables[SelectorComponentContext Template Variables]).
|===
You can pre-select an item by defining it to get exposed. This is
useful if you know the default and lets the user merely press `Enter` to make a choice.
The following listing sets a default:
[source, java, indent=0]
----
include::{snippets}/UiComponentSnippets.java[tag=snippet8]
----