String Input
The string input component asks a user for simple text input, optionally masking values
if the content contains something sensitive. The input can also be required (at least 1 char).
The following listing shows an example:
@Component
public class ComponentCommands {
private final Terminal terminal;
private final ResourceLoader resourceLoader;
private final TemplateExecutor templateExecutor;
public ComponentCommands(Terminal terminal, ResourceLoader resourceLoader,
TemplateExecutor templateExecutor) {
this.terminal = terminal;
this.resourceLoader = resourceLoader;
this.templateExecutor = templateExecutor;
}
@Command(name = "component string", description = "String input", group = "Components")
public String stringInput(@Option(defaultValue = "false") boolean mask) {
StringInput component = new StringInput(terminal, "Enter value", "myvalue");
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
if (mask) {
component.setMaskCharacter('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getMaskedResultValue();
}
}
The following screencast shows typical output from a string input component:
The context object is StringInputContext. The following table lists its context variables:
| Key | Description |
|---|---|
|
The default value, if set. Otherwise, null. |
|
The masked input value |
|
The masked result value |
|
The mask character, if set. Otherwise, null. |
|
|
|
|
|
The parent context variables (see TextComponentContext Template Variables). |