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

String Input

The string input component asks a user for simple text input, optionally masking values if the content contains something sensitive. The following listing shows an example:spring-doc.cn

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

	@ShellMethod(key = "component string", value = "String input", group = "Components")
	public String stringInput(boolean mask) {
		StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
		component.setResourceLoader(getResourceLoader());
		component.setTemplateExecutor(getTemplateExecutor());
		if (mask) {
			component.setMaskCharacter('*');
		}
		StringInputContext context = component.run(StringInputContext.empty());
		return "Got value " + context.getResultValue();
	}
}

The following screencast shows typical output from a string input component:spring-doc.cn

The context object is StringInputContext. The following table lists its context variables:spring-doc.cn

Table 1. StringInputContext Template Variables
Key Description

defaultValuespring-doc.cn

The default value, if set. Otherwise, null.spring-doc.cn

maskedInputspring-doc.cn

The masked input valuespring-doc.cn

maskedResultValuespring-doc.cn

The masked result valuespring-doc.cn

maskCharacterspring-doc.cn

The mask character, if set. Otherwise, null.spring-doc.cn

hasMaskCharacterspring-doc.cn

true if a mask character is set. Otherwise, false.spring-doc.cn

modelspring-doc.cn

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