確認

確認コンポーネントは、ユーザーに簡単な確認を求めます。それは本質的にイエスかノーの質問です。

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

	@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
	public String confirmationInput(boolean no) {
		ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
		component.setResourceLoader(getResourceLoader());
		component.setTemplateExecutor(getTemplateExecutor());
		ConfirmationInputContext context = component.run(ConfirmationInputContext.empty());
		return "Got value " + context.getResultValue();
	}
}

次のスクリーンキャストは、確認コンポーネントからの一般的な出力を示しています。

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

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

defaultValue

デフォルト値 —  true または false のいずれか。

model

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