このバージョンはまだ開発中であり、まだ安定しているとは見なされていません。最新の安定バージョンについては、Spring Shell 3.4.1 を使用してください!

数値入力

数値入力コンポーネントは、ユーザーに単純な数値入力を求めます。Number.class の任意の実装を使用するように設定できます。次のリストに例を示します。

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:

コンテキストオブジェクトは NumberInputContext です。次の表に、そのコンテキスト変数を示します。

表 1: NumberInputContext テンプレート変数
キー 説明

defaultValue

設定されている場合のデフォルト値。それ以外の場合は null。

defaultClass

The default number class to use, if set. Otherwise, Integer.class.

required

true if the input is required. Otherwise, false.

model

親コンテキスト変数 ( TextComponentContext テンプレート変数を参照)。