Number Input

The number input component asks a user for simple number input. It can be configured to use any implementation of Number.class. The following listing shows an example:spring-doc.cn

NumberInput component = new NumberInput(getTerminal(), "Enter value", 99.9, Double.class);
ResourceLoader resourceLoader = null; // getResourceLoader();
TemplateExecutor templateExecutor = null; // getTemplateExecutor();
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);

NumberInputContext context = component.run(NumberInputContext.empty());
return "Got value " + context.getResultValue();

The following image shows typical output from a number input component:spring-doc.cn

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

Table 1. NumberInputContext Template Variables
Key Description

defaultValuespring-doc.cn

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

defaultClassspring-doc.cn

The default number class to use, if set. Otherwise, Integer.class.spring-doc.cn

requiredspring-doc.cn

true if the input is required. Otherwise, false.spring-doc.cn

modelspring-doc.cn

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