Single Select

单选组件要求用户从列表中选择一个项目。它类似于简单的下拉框实现。以下列表显示了一个示例:

link:../../../../../src/test/java/org/springframework/shell/docs/UiComponentSnippets.java[role=include]

以下屏幕截图显示了单选组件的典型输出:

link:example$component-single-select-1.cast[role=include]

context 对象是 SingleItemSelectorContext。下表描述了其上下文变量:

Table 1. SingleItemSelectorContext Template Variables
Key Description

value

组件存在时的返回值。

rows

可见项目,行中包含名称和所选项目映射。

model

父上下文变量(请参阅 SelectorComponentContext Template Variables)。

你可以通过定义一项来预先选中它以供显示。如果你知道默认设置,这样很有用且可以让用户只需按 Enter 即可做出选择。以下列表设置一个默认值:

link:../../../../../src/test/java/org/springframework/shell/docs/UiComponentSnippets.java[role=include]