This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.3.3!spring-doc.cn

Multi Select

The multi select component asks a user to select multiple items from a list. The following listing shows an example:spring-doc.cn

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

	@ShellMethod(key = "component multi", value = "Multi selector", group = "Components")
	public String multiSelector() {
		List<SelectorItem<String>> items = new ArrayList<>();
		items.add(SelectorItem.of("key1", "value1"));
		items.add(SelectorItem.of("key2", "value2", false, true));
		items.add(SelectorItem.of("key3", "value3"));
		MultiItemSelector<String, SelectorItem<String>> component = new MultiItemSelector<>(getTerminal(),
				items, "testSimple", null);
		component.setResourceLoader(getResourceLoader());
		component.setTemplateExecutor(getTemplateExecutor());
		MultiItemSelectorContext<String, SelectorItem<String>> context = component
				.run(MultiItemSelectorContext.empty());
		String result = context.getResultItems().stream()
				.map(si -> si.getItem())
				.collect(Collectors.joining(","));
		return "Got value " + result;
	}
}

The following screencast shows a typical multi-select component:spring-doc.cn

The context object is MultiItemSelectorContext. The following table describes its context variables:spring-doc.cn

Table 1. MultiItemSelectorContext Template Variables
Key Description

valuesspring-doc.cn

The values returned when the component exists.spring-doc.cn

rowsspring-doc.cn

The visible items, where rows contain maps of name, selected, on-row, and enabled items.spring-doc.cn

modelspring-doc.cn

The parent context variables (see SelectorComponentContext Template Variables).spring-doc.cn