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");
}
}
});
精彩评论