Community
Participate
Working Groups
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
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.
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.
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.
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.
(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
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.
Released >20061005. Thanks, Brad!
forgot to set this to fixed...