文字列入力
文字列入力コンポーネントは、ユーザーにシンプルなテキスト入力を求めます。コンテンツに機密情報が含まれている場合は、必要に応じて値をマスクします。入力は必須(1 文字以上)にすることもできます。
次のリストに例を示します。
public class ComponentCommands {
@Command(name = "component string", description = "String input", group = "Components")
public String stringInput(boolean mask) {
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
ResourceLoader resourceLoader = null; // getResourceLoader();
TemplateExecutor templateExecutor = null; // getTemplateExecutor();
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
if (mask) {
component.setMaskCharacter('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getResultValue();
}
}次のスクリーンキャストは、文字列入力コンポーネントからの一般的な出力を示しています。
コンテキストオブジェクトは StringInputContext です。次の表に、そのコンテキスト変数を示します。
| キー | 説明 |
|---|---|
| 設定されている場合のデフォルト値。それ以外の場合は null。 |
| マスクされた入力値 |
| マスクされた結果値 |
| マスク文字 (設定されている場合)。それ以外の場合は null。 |
|
|
|
|
| 親コンテキスト変数 ( TextComponentContext テンプレート変数を参照)。 |