Home » Eclipse Projects » Eclipse Platform » Binding the attribute of a bean object wrapped in a WritableValue object
Binding the attribute of a bean object wrapped in a WritableValue object [message #328347] |
Thu, 22 May 2008 14:58 |
Hao Missing name Messages: 115 Registered: July 2009 |
Senior Member |
|
|
I have a java bean such as Contact which has attributes such as name,
address, email. The object presented to my code is a Wrapped WritableValue
object, i.e. IObservableValue.
For instance,
IObservableValue contactObservable = new WritableValue(new Contact(),
Contact.class);
I tried to bind the name attributed of Contact bean wrapped in
contactObservable to a text field. I did the following:
IObservableValue bindedNameTextObserveWidget =
SWTObservables.observeText(text);
IObservableValue selectedContactNameObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(), contactObservable,
"name", java.lang.String.class);
bindingContext.bindValue(bindedNameTextObserveWidget, contactObservable,
null, null);
I did not get any error but this kind of binding does not work.
Any one knows how to bind the attribute of a writableValue object to a gui
field instead of binding the attribute of a java bean to a gui field.
|
|
|
[DataBinding] Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328348 is a reply to message #328347] |
Thu, 22 May 2008 16:22 |
Matthew Hall Messages: 368 Registered: July 2009 |
Senior Member |
|
|
Hao wrote:
> IObservableValue bindedNameTextObserveWidget =
> SWTObservables.observeText(text);
> IObservableValue selectedContactNameObserveDetailValue =
> BeansObservables.observeDetailValue(Realm.getDefault(),
> contactObservable, "name", java.lang.String.class);
>
> bindingContext.bindValue(bindedNameTextObserveWidget,
> contactObservable, null, null);
It looks like you're binding to the wrong observable. You have:
bindingContext.bindValue(bindingNameTextObserveWidget,
contactObservable, // <-- wrong observable
null,
null);
But I think it should be:
bindingContext.bindValue(bindingNameTextObserveWidget,
selectedContactNameObserveDetailValue,
null,
null);
Matthew
|
|
| |
Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328367 is a reply to message #328347] |
Fri, 23 May 2008 11:37 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi Hao,
are you binding the "name" attribute to an SWT Text instance (and not
a Label or so)? If so, SWTObservables#observeText(Control) is the wrong
method as it does not apply to Text instances. Instead, you should use
the method SWTObservables#observeText(Control, int). In the methods'
JavaDoc you can see which controls are supported by the individual
methods.
However, using the wrong method above should result in an exception being
thrown so maybe this is not your problem...
Regards,
Ovidio
Hao wrote:
> I have a java bean such as Contact which has attributes such as name,
> address, email. The object presented to my code is a Wrapped
> WritableValue object, i.e. IObservableValue. For instance,
> IObservableValue contactObservable = new WritableValue(new Contact(),
> Contact.class);
>
> I tried to bind the name attributed of Contact bean wrapped in
> contactObservable to a text field. I did the following:
>
> IObservableValue bindedNameTextObserveWidget =
> SWTObservables.observeText(text);
> IObservableValue selectedContactNameObserveDetailValue =
> BeansObservables.observeDetailValue(Realm.getDefault(),
> contactObservable, "name", java.lang.String.class);
>
> bindingContext.bindValue(bindedNameTextObserveWidget,
> contactObservable, null, null);
>
> I did not get any error but this kind of binding does not work.
>
> Any one knows how to bind the attribute of a writableValue object to a
> gui field instead of binding the attribute of a java bean to a gui field.
>
>
>
|
|
|
Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328393 is a reply to message #328367] |
Fri, 23 May 2008 19:04 |
Matthew Hall Messages: 368 Registered: July 2009 |
Senior Member |
|
|
That could be the problem. Try this:
IObservableValue bindedNameTextObserveWidget =
SWTObservables.observeText(text, SWT.Modify);
Matthew
Ovidio Mallo wrote:
> Hi Hao,
>
> are you binding the "name" attribute to an SWT Text instance (and not
> a Label or so)? If so, SWTObservables#observeText(Control) is the wrong
> method as it does not apply to Text instances. Instead, you should use
> the method SWTObservables#observeText(Control, int). In the methods'
> JavaDoc you can see which controls are supported by the individual
> methods.
>
> However, using the wrong method above should result in an exception being
> thrown so maybe this is not your problem...
>
> Regards,
> Ovidio
>
> Hao wrote:
>> I have a java bean such as Contact which has attributes such as name,
>> address, email. The object presented to my code is a Wrapped
>> WritableValue object, i.e. IObservableValue. For instance,
>> IObservableValue contactObservable = new WritableValue(new Contact(),
>> Contact.class);
>>
>> I tried to bind the name attributed of Contact bean wrapped in
>> contactObservable to a text field. I did the following:
>>
>> IObservableValue bindedNameTextObserveWidget =
>> SWTObservables.observeText(text);
>> IObservableValue selectedContactNameObserveDetailValue =
>> BeansObservables.observeDetailValue(Realm.getDefault(),
>> contactObservable, "name", java.lang.String.class);
>>
>> bindingContext.bindValue(bindedNameTextObserveWidget,
>> contactObservable, null, null);
>>
>> I did not get any error but this kind of binding does not work.
>>
>> Any one knows how to bind the attribute of a writableValue object to a
>> gui field instead of binding the attribute of a java bean to a gui field.
>>
>>
>>
|
|
|
Goto Forum:
Current Time: Sun Oct 20 13:10:29 GMT 2024
Powered by FUDForum. Page generated in 0.02741 seconds
|