How to get notified when a field is dirty?

31 views
Skip to first unread message

FrankGWT

unread,
Jul 28, 2010, 9:07:00 PM7/28/10
to GWT Pectin


in my application I need to detect if a field is dirty or not. By
default, the BeanModelProvider only can tell me the whole FormModel
has been modified or not.

for a FieldModel, I try to use the
FieldModel.addValueChangeHandler(...) method, but it fires whenever
the value in the fieldmodel changed, even the value is changed back
to the original value.

Is there a way to tell if a field has been modified or not? I think
the BeanModelProvider must be tracking all of the field changes. But I
just don't know how to get that info out of it.

Thanks a lot!

Andrew

unread,
Jul 28, 2010, 10:40:02 PM7/28/10
to GWT Pectin
Howdy,

The value models returned by the BeanModelProvider all have a
`ValueModel<Boolean> getDirtyModel()` method that you can call.
Currently there's no way to get at this directly from a FieldModel so
you'll have to do it manually.

i.e. instead of:
fieldOfType(String.class).boundTo(provider, "propertyName");

you'll need to go:
BeanPropertyValueModel<String> beanModel =
provider.getValueModel("propertyName", String.class);
ValueModel<Boolean> dirty = beanModel.getDirtyModel();
fieldOfType(String.class).boundTo(beanModel);

Which is unfortunately a bit ugly.

Feel free to raise an issue for this with an example of how you're
using it. It might be worth while adding a `ValueModel<Boolean>
FieldModel.dirty()` that delegates to the underlying value model if it
implements something like `HasDirtyModel`.

Cheers
Andrew
Reply all
Reply to author
Forward
0 new messages