PDA

View Full Version : KeyListener not working in Tomcat



jamone
23 Dec 2011, 6:46 PM
I am developing in Eclipse Indigo, deploying to Tomcat 7.0, using gwt 2.4.0 SDK and gxt-2.2.5. It is a simple login dialog box. In Eclipse the KeyListeners for the Username and Password fields function fine, however when it is deployed to Tomcat, these KeyListeners do not function. Is there some problem with Listeners in Tomcat?

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Status;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class LoginDialog extends Dialog {

public TextField<String> userName;
public TextField<String> passWord;
protected Button login;
protected Button reset;
public Status status;
public int loginAttempts = 0;
protected LoginInfo result = null;

// Constructor for the class
public LoginDialog() {
FormLayout layout = new FormLayout();
layout.setLabelWidth(90);
layout.setDefaultWidth(155);
setLayout(layout);

setButtonAlign(HorizontalAlignment.LEFT);
setButtons("");
setIcon(IconHelper.createStyle("user"));
setHeading("Data Management Login");
setModal(true);
setBodyBorder(true);
setBodyStyle("padding: 8px;background: none");
setWidth(300);
setResizable(false);

KeyListener keyListener = new KeyListener() {
public void componentKeyUp(ComponentEvent ce) {
validate();
}
};

KeyListener keyListenerPasswd = new KeyListener() {
public void componentKeyUp(ComponentEvent ce) {
validate();
}

public void componentKeyDown(ComponentEvent event) {
if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
MessageBox.alert("Key Alert", "Enter key pressed", null);
onSubmit(loginAttempts, result);
}
}
};

userName = new TextField<String>();
userName.setMinLength(5);
userName.setFieldLabel("Username");
userName.setLabelStyle("color: black;");
userName.setAllowBlank(false);
userName.getMessages().setBlankText("Please enter a user name");
userName.addKeyListener(keyListener);
add(userName);

passWord = new TextField<String>();
passWord.setMinLength(6);
passWord.setPassword(true);
passWord.setFieldLabel("Password");
passWord.setLabelStyle("color: black;");
passWord.setAllowBlank(false);
passWord.addKeyListener(keyListenerPasswd);
add(passWord);

setFocusWidget(userName);
}

@Override
protected void createButtons() {
super.createButtons();
status = new Status();
status.setBusy("Please wait...");
status.setStylePrimaryName("col_header");
status.hide();
status.setAutoWidth(true);
getButtonBar().add(status);

getButtonBar().add(new FillToolItem());

reset = new Button("Reset");
reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent be) {
userName.reset();
passWord.reset();
validate();
userName.focus();
}
});

login = new Button("Login");
login.disable();
login.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent be) {
onSubmit(loginAttempts, result);
}
});

addButton(login);
addButton(reset);
}
}

KeyListener and KeyListenerPassword do not fire when this is deployed in Tomcat, the Tomcat war file is built using ant.

Has anyone else encountered a similar problem? Can anyone suggest what may be occurring here and a solution.

Thanks in advance.

Cheers

oxyrox
26 Jan 2012, 2:20 AM
Hi!

I don't think that Tomcat is responsible for this one... ;)
But I had similar issues quite some time ago.

By


In Eclipse the KeyListeners for the Username and Password fields function fine

you mean in Dev Mode, right?

On what browsers have tried this so far? When building, are you compiling your app for all user agents?
Or maybe... just maybe... the cache is messing up your app ;)

Greets,
oxy