Number Input
The number input component asks a user for simple number input. It supports Byte, Short, Integer, Long, Float, Double, BigInteger, and BigDecimal. 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 number", description = "Number input", group = "Components")
public String numberInput() {
NumberInput component = new NumberInput(terminal, "Enter value", 99.9, Double.class);
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
NumberInputContext context = component.run(NumberInputContext.empty());
return "Got value " + context.getResultValue();
}
}
The following screencast shows typical output from a number input component:
The context object is NumberInputContext. The following table lists its context variables:
| Key | Description |
|---|---|
|
The default value, if set. Otherwise, null. |
|
The default number class to use, if set. Otherwise, Integer.class. |
|
|
|
The parent context variables (see TextComponentContext Template Variables). |