Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling and Disabling Save button on a GWT page

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.

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.

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?

like image 853
Tihom Avatar asked Jun 23 '10 03:06

Tihom


2 Answers

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());
  }
}

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...

like image 137
Jla Avatar answered Oct 05 '22 23:10

Jla


Check out the GWT articles on MVP
http://code.google.com/webtoolkit/articles/mvp-architecture.html
http://code.google.com/webtoolkit/articles/mvp-architecture-2.html

Specifically the part on Events and the Event Bus.

Also look at this http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/8b0ae5eaf84d8bc2?hide_quotes=no

like image 42
Romain Hippeau Avatar answered Oct 06 '22 01:10

Romain Hippeau