Multi Select

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

@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:

The context object is MultiItemSelectorContext. The following table describes its context variables:

Table 1. MultiItemSelectorContext Template Variables
Key Description

values

The values returned when the component exists.

rows

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

model

The parent context variables (see SelectorComponentContext Template Variables).