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