確認
確認元件要求使用者進行簡單確認。它本質上是一個是或否的問題。
@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。下表描述了其上下文變數
| 鍵 | 描述 |
|---|---|
|
預設值—— |
|
父上下文變數(參見TextComponentContext 模板變數)。 |