GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert() [英] GXT KeyListener.componentKeyDown() immediately closes MessageBox.alert()

查看:112
本文介绍了GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In GXT, MessageBox methods are asynchronous, meaning that the application does not "lock up" while the message box is displayed.

我使用KeyListener处理表单中的Enter键(以提高可用性,即允许使用Enter键提交表单),随后在应用程序处理用户凭据时禁用表单字段.如果它们不正确,则显示MessageBox.alert(),然后重新启用表单字段.但是,由于alert()立即返回,因此表单字段立即又变得可用,从而允许用户在不关闭警报的情况下输入数据.

I using a KeyListener to process enter key presses in a form (to increase usability, i.e., allowing the form to be submitted by the enter key) and subsequently disabling the form fields while the application processes the user's credentials. If they are incorrect, I show a MessageBox.alert() and then re-enable the form fields. However, since alert() returns immediately, the form fields are immediately made available again, allowing the user to input data without closing the alert.

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

The solution is to use a callback in alert(); however, the enter keypress not only causes the form to submit, but also causes the alert to immediately dismiss (as if both the form and the message box are processing the enter key). How do I keep the alert box open until the user presses enter a second time or clicks the "Ok" button?

推荐答案

密钥由

使用此类可以使用addCommand(Command)addCommand(IncrementalCommand)方法在所有当前待处理的事件处理程序完成之后执行代码.当您需要在当前堆栈的上下文之外执行代码时,这很有用.

This class allows you to execute code after all currently pending event handlers have completed, using the addCommand(Command) or addCommand(IncrementalCommand) methods. This is useful when you need to execute code outside of the context of the current stack.

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

这篇关于GXT KeyListener.componentKeyDown()立即关闭MessageBox.alert()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆