確認

確認元件向用戶詢問一個簡單的確認。它本質上是一個是或否的問題。

@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

預設值 — truefalse

模型

父上下文變數 (參見 TextComponentContext 模板變數)。