亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在瓦丁中使用狀態更改通知程序進行驗證?

如何在瓦丁中使用狀態更改通知程序進行驗證?

陪伴而非守候 2022-09-21 17:36:29
我正在使用綁定器來綁定和驗證 和 .為了獲得驗證更改的通知,我向綁定程序添加了一個狀態更改通知程序。偵聽器檢查是否返回 false。但是,在組合框中選擇有效條目但文本字段中的無效條目后,它將返回 false。因此,即使存在驗證錯誤,它也返回 false。有關最小示例,請參見下文。TextFieldComboBox.hasValidationErrors()public class TestWindow extends Window {    private final Binder<State> binder;    public TestWindow() {        this.binder  = new Binder<>();        ComboBox<String> comboBox = new ComboBox<>("comboBox", List.of("A", "B"));        TextField textField = new TextField("textField");        this.binder.forField(comboBox).bind(State::getComboBox, State::setComboBox);        this.binder.forField(textField)                .withValidator(string -> string.length() > 3, "tmp")                .bind(State::getName, State::setName);        this.binder.addStatusChangeListener( status -> System.err.println(status.hasValidationErrors()));        setContent(new VerticalLayout(comboBox, textField));    }    private class State {        private String name;        private String comboBox;        public State(String name, String comboBox) {            this.name = name;            this.comboBox = comboBox;        }        public String getComboBox() {            return this.comboBox;        }        public void setComboBox(String comboBox) {            this.comboBox = comboBox;        }        public String getName() {            return this.name;        }        public void setName(String name) {            this.name = name;        }    }}在文本字段中輸入一個太短的字符串并在組合框中選擇某些內容后,我希望打印出來。true
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

您只是在檢查最近更改的組件的值是否有效。如果要檢查綁定組件是否存在任何驗證錯誤,請使用 。binder.isValid()

 binder.addStatusChangeListener(status -> System.err.println(binder.isValid()));

請注意,您的布爾值現在是反轉的。

您可以在官方文檔中找到很多有用的示例:將數據綁定到表單


查看完整回答
反對 回復 2022-09-21
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號