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?
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...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With