Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 140644 - [DataBinding] Binding to ValidationError of DataBindingContext is broken
Summary: [DataBinding] Binding to ValidationError of DataBindingContext is broken
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 154132
  Show dependency tree
 
Reported: 2006-05-08 15:19 EDT by Nicolas Gouy CLA
Modified: 2006-10-05 09:11 EDT (History)
3 users (show)

See Also:


Attachments
patch (11.50 KB, patch)
2006-10-05 00:11 EDT, Brad Reynolds CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Gouy CLA 2006-05-08 15:19:10 EDT
Hello, I wanted to bind the ValidationError Observable to a Widget, and it doesn't seem to work.
I tested with Jface Databinding sample and in TestMasterDetails.java example, instead of binding the simple date error to a label, I bound the ValidationError of DBC to the Label (with a simple converter).
		dbc.bind(validationError, dbc.getValidationError(),	new BindSpec().setUpdateModel(false).setModelToTargetConverter(new IConverter() {

			public Object convert(Object fromObject) {
				// TODO Auto-generated method stub
				if (fromObject == null) return null;
				return ((ValidationError) fromObject).message;
			}

			public Object getFromType() {
				// TODO Auto-generated method stub
				return Object.class;
			}

			public Object getToType() {
				// TODO Auto-generated method stub
				return String.class;
			}
			
		}));

After investigating, I saw the ValidationError is a computed value (very interesting concept and useful) on the ValidationErrorList.
1. The ComputedValue mechanism seems to use the StateListener to the Object, but I don't see any management of staleness in ValidationErrorList (or ObservableList).
2. When one of the field gets an error, I debug and saw the ChangedListener on my binding was null (whereas the ValidationErrorList registers listeners on them). At the beginning, it's registered, the removed and not added again when needed.

I have not enough time to go deeper in the mechanism, could you help me to understand what I'm doing wrong with this simple binding (With previous releases I was already binding with that mechanism and it worked).
Is there an other way to do this? (My workaround is a listener on DBC, but I would prefer to use ValidationError Computed value).

Thanks in advance
Comment 1 Boris Bokowski CLA 2006-05-08 15:36:19 EDT
This looks like a bug in the current code. Thanks for reporting this! Unfortunately, we are extremely busy with the 3.2 release right now, so it will take some time before I can investigate this.
Comment 2 Matt Carter CLA 2006-07-21 17:28:07 EDT
I can confirm this binding dbc.getValidationError() to a Label. I have found a workaround, but it makes no sense. When it doesn't work, nothing is shown in the control.

--- This doesn't work:

dbc = createContext(); // (as per example)
dbc.bind(label, dbc.getValidationError(), null);

--- This doesn't work:

dbc = createContext();
dbc.addBindingEventListener(this);
dbc.bind(label, dbc.getValidationError(), null);

..with..

public ValidationError bindingEvent(BindingEvent e) {
    String x = e.toString();
    return null; // or e.validationError..
}

--- This DOES work:

dbc = createContext();
dbc.addBindingEventListener(this);
dbc.bind(label, dbc.getValidationError(), null);

..with..

public ValidationError bindingEvent(BindingEvent e) {
    String x = e.toString();
    return null;
}

How on earth can doing a toString() make it work? Originally I was printing a log message and have wittled it down to this.
Comment 3 Matt Carter CLA 2006-07-21 18:03:52 EDT
CORRECTION:

doesn't work 2 should look like this:

public ValidationError bindingEvent(BindingEvent e) {
    return null;
}

i.e. no String x = e.toString();, just an empty method.
Comment 4 Boris Bokowski CLA 2006-10-04 13:04:33 EDT
Does the patch from bug 158065 resolve this?

Brad, given your interest in this, could you write a small snippet that demonstates binding the validation error to a label?  Once we get it to work, it would be a good snippet to have.
Comment 5 Brad Reynolds CLA 2006-10-04 13:52:19 EDT
(In reply to comment #4)
> Does the patch from bug 158065 resolve this?
> 
I'll take a look at this tonight.

> Brad, given your interest in this, could you write a small snippet that
> demonstates binding the validation error to a label?  Once we get it to work,
> it would be a good snippet to have. 

will do
Comment 6 Brad Reynolds CLA 2006-10-05 00:11:14 EDT
Created attachment 51452 [details]
patch

I didn't use the patch from bug 158065 as it didn't seem to be the issue, at least not for what I was testing.  The problem was that when bindings are created, either from bindValue(...) or bindList(...), the binding wasn't being added to the internal bindings list thus they weren't being observed.

I added tests for adding the binding to the internal list and also for receiving change events from the validation error/errors.  I'm going to post a question to bug 158065 to get some clarification as to what it's meant to solve.

In the patch is also a snippet for binding the validation error to a Label's text property.
Comment 7 Boris Bokowski CLA 2006-10-05 09:11:06 EDT
Released >20061005. Thanks, Brad!
Comment 8 Boris Bokowski CLA 2006-10-05 09:11:35 EDT
forgot to set this to fixed...