Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert()_Gwt_Messagebox_Gxt_Keylistener - Fatal编程技术网

Gwt GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert()

Gwt GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert(),gwt,messagebox,gxt,keylistener,Gwt,Messagebox,Gxt,Keylistener,在GXT中,MessageBox方法是异步的,这意味着在显示消息框时应用程序不会“锁定” I使用KeyListener处理表单中的enter键(以提高可用性,即允许通过enter键提交表单),然后在应用程序处理用户凭据时禁用表单字段。如果它们不正确,我将显示一个MessageBox.alert(),然后重新启用表单字段。但是,由于alert()会立即返回,因此表单字段会立即再次可用,使用户可以在不关闭警报的情况下输入数据 解决方案是在alert()中使用回调;但是,enter键不仅会导致表单提交

在GXT中,
MessageBox
方法是异步的,这意味着在显示消息框时应用程序不会“锁定”

I使用
KeyListener
处理表单中的enter键(以提高可用性,即允许通过enter键提交表单),然后在应用程序处理用户凭据时禁用表单字段。如果它们不正确,我将显示一个
MessageBox.alert()
,然后重新启用表单字段。但是,由于
alert()
会立即返回,因此表单字段会立即再次可用,使用户可以在不关闭警报的情况下输入数据


解决方案是在
alert()
中使用回调;但是,enter键不仅会导致表单提交,还会导致警报立即消失(就好像表单和消息框都在处理enter键一样)。在用户再次按下enter键或单击“确定”按钮之前,如何保持警报框打开?

该键是由以下人员提供的
DeferredCommand

此类允许您在所有当前挂起的事件处理程序完成后,使用
addCommand(Command)
addCommand(IncrementalCommand)
方法执行代码。当您需要在当前堆栈的上下文之外执行代码时,这非常有用

if(!validate())
{
    DeferredCommand.addCommand(new Command() {
        public void execute() {
            MessageBox.alert("Error", "You must enter a username and password.", alertListener);
            return;
        }
    });
}