1

I want to do validation for EditTextCell widget in the grid. So I am trying to extend the EditTextCell and add a value change listener to the same, so that I can continue with the validation. But I am unable to add the same. Any help would be appreciated. Am using GWT 2.4.0

My code looks like this.

public class MyEditTextCell extends EditTextCell { 
        public MyEditTextCell() { 
            super(); 
            onValueChange( new ValueChangeHandler<String>() { 
                @Override public void onValueChange( ValueChangeEvent event ) { 
                    Window.alert( "jsdfk" ); 
                } 
            } ); 
        } 
        private void onValueChange( ValueChangeHandler<String> valueChangeHandler ) { 
            Window.alert( "jsdfk" ); 
        } 
    }   
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Abhijith Nagaraja
  • 3,370
  • 6
  • 27
  • 55
  • "But I am unable to add the same." What have you tried ? Provide Code or error stack trace – Hardik Mishra Apr 11 '12 at 04:49
  • public class MyEditTextCell extends EditTextCell { public MyEditTextCell() { super(); onValueChange( new ValueChangeHandler() { @Override public void onValueChange( ValueChangeEvent event ) { Window.alert( "jsdfk" ); } } ); } private void onValueChange( ValueChangeHandler valueChangeHandler ) { Window.alert( "jsdfk" ); } } – Abhijith Nagaraja Apr 11 '12 at 05:22

1 Answers1

1

It seems like the only adequate way to do this with EditTextCell is to override onBrowserEvent() similarly to private editEvent() method of EditTextCell class.

public void onBrowserEvent(Context context, Element parent, String value,
      NativeEvent event, ValueUpdater valueUpdater) {
          super.onBrowserEvent(context, parent, value, event, valueUpdater);
          String type = event.getType();
          if ("keyup".equals(type) || "keydown".equals(type) || "blur".equals(type) {
              validateValue();
          }
  }

But listening keyup, keydown and blur event doesn't guarantee handling actual change. If you don't want to skip any changes(for example pasting text by context right-click menu) you should to add com.google.gwt.user.client.Timer which checks value. Timer should be ran on focus and stoped on blur.

If you want to code in 'event way' 1) replace validateValue() by ValueChangeEvent.fire(this, vale); 2) add to your MyEditTextCEll interface HasValueChangeHandlers and implement it like this

public HandlerRegistration addValueChangeHandler(
      ValueChangeHandler<String> handler) {
    return addHandler(handler, ValueChangeEvent.getType());
  }
cardamo
  • 853
  • 4
  • 13