开发者

GWT checking if textbox is empty

Im working on a school p开发者_StackOverflow中文版roject and i'm trying to check in GWT if a textbox i create is empty or not. I have done the exact same thing on another project and there it worked fine. i have searched for the answer here and on google but couldn't find any answer.

voornaamTB = new TextBox();
voornaamTB.setText(null);

ok.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (voornaamTB != null) {
                System.out.println("not empty");
            } else {
                System.out.println("empty");
            }
        }
    });


Something like:

if(!voornaamTB.getText().isEmpty()) { ...

will work. You're currently testing to see whether the TextBox itself is null, which it isn't as you initialized it on the first line.

You probably don't need the setText(null) after immediately creating it.


Your object is not empty, so you can get only not empty. try this

voornaamTB = new TextBox();
voornaamTB.setText(null);

ok.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (voornaamTB.getText() != null) {
                System.out.println("not empty");
            } else {
                System.out.println("empty");
            }
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜