启用和禁用GWT页面上的保存按钮 [英] Enabling and Disabling Save button on a GWT page

查看:119
本文介绍了启用和禁用GWT页面上的保存按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的应用程序具有许多文本框的设置数据页面;每个页面都有一个保存按钮。我已将大部分页面定义为* .ui.xml文件,并使用GWT 2.0 UI绑定。

The application I am working on has pages of setup data with lots of textboxes; each page having a save button. I have defined most of the pages as a *.ui.xml file and used the GWT 2.0 UI binding.

我想添加一个禁用onload的保存按钮只有在用户将数据修改为其中一个文本框后才能启用。

I would like to add a save button which is disabled onload and is only enabled after a user modifies the data into one of the textboxes.

我知道我可以在页面上的每个元素上注册一个事件处理程序来启用该按钮,但我想要一个更优雅的解决方案。理想情况下,我想定义一个按钮来监听页面上的事件并进行更改。您可以使用将更改事件添加到整个包含的窗口小部件中,这样可以在GWT中实现?

I know I can register an event handler against each element on the page to enable the button, but I wanted a more elegant solution. Ideally, I would like to define a button that "listens" to events on the page and changes itself. Is this possible in GWT?

推荐答案

addDomHandler

You can also add the change event to your whole containing widget using addDomHandler

public class SetupDataPage extends Composite{

  // Binder stuff  

  // Button from the binder
  @UiField Button saveBtn;

  public SetupDataPage(){
        addDomHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent event) {
                saveBtn.setEnabled(true);
            }
        }, ChangeEvent.getType());
  }
}

小心这将触发SetupDataPage中所有文本框的事件。另一方面,某些特定的小部件可能不起作用。我知道它适用于GWT的文本框,复选框,列表框...

Beware This will trigger the event for all textboxes in SetupDataPage. On the other side it might not work for some specific widgets. I know it works for GWT's textbox, checkbox, listbox...

这篇关于启用和禁用GWT页面上的保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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