I have a page in GWT with several "Edit" buttons. I added a login dialog box. By default the button are disabled.
What I want to do is enable buttons only after user logged in.
Also, as soon as I put several operators in if clause, it stops working. If I put only loggedIn = true , then it works (I mean it goes out of if clause and continues).
I'm using global boolean variable:
Boolean loggedIn = false;
Here is what I do:
public void login(final VerticalPanel vp, final RootPanel rp) {
final DialogBox db = new DialogBox();
db.setAnimationEnabled(true);
db.setGlassEnabled(true);
final VerticalPanel vp0 = new VerticalPanel();
vp0.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
vp0.setWidth("100%");
final HTML loginLabel = new HTML("Login:");
loginLabel.setStyleName("h1");
final FlexTable ft0 = new FlexTable();
final FlexCellFormatter cf = ft0.getFlexCellFormatter();
ft0.setCellSpacing(10);
ft0.setHTML(0, 0, "Login:");
cf.setStyleName(0, 0, "h3");
cf.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
final TextBox loginBox = new TextBox();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loginBox.setFocus(true);
}
});
ft0.setWidget(0, 1, loginBox);
ft0.setHTML(1, 0, "Password:");
cf.setStyleName(1, 0, "h3");
cf.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
final PasswordTextBox passwordBox = new PasswordTextBox();
ft0.setWidget(1, 1, passwordBox);
final Button loginButton = new Button(
"Login", new ClickHandler() {
public void onClick(ClickEvent event) {
if ((loginBox.getText() == "1234") && passwordBox.getText() == "1234") {
final HTML loginSuccessMsg = new HTML("Logged in. Please wait...");
db.add(loginSuccessMsg);
loggedIn = true;
db.hide();
rp.clear();
rp.add(vp);
}
else {
final HTML loginErrorMsg = new HTML("Username/Password incorrect! Try again.");
db.add(loginErrorMsg);
}
}
}
);
passwordBox.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
if (((int)event.getCharCode()) == 13) {
loginButton.click();
}
}
});
ft0.setWidget(2, 0, loginButton);
cf.setColSpan(2, 0, 2);
cf.setAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
vp0.add(ft0);
db.add(vp0);
int left = Window.getClientWidth() / 3;
int top = Window.getClientHeight() / 3;
db.setPopupPosition(left, top);
db.show();
//vp.add(vp0);
}
This is login method.
And here is where I use loggedIn variable:
if (loggedIn) butTotalNumQuick.setEnabled(true); else butTotalNumQuick.setEnabled(false);
Also, some more details - this button is disabled by default, so this works.
I think the problem is in the fact that page (panel) needs to be refreshed after login. This is what I tried to do with
rp.clear();
rp.add(vp);
where rp is RootPanel