|
Re: [Databinding/E4] Binding of nested properties [message #1740310 is a reply to message #1738752] |
Thu, 11 August 2016 13:09 |
Ralf Heydenreich Messages: 235 Registered: July 2009 |
Senior Member |
|
|
Am 23.07.2016 um 02:05 schrieb Ralf Heydenreich:
> Hi all,
> I've an editor (MPart) which has a bound model. The model is, e.g., a
> person with an address and an alternative address.
>
> Like so:
>
> +----------------------------+
> | Person |
> +----------------------------+
> | name: String |
> | surname: String |
> | alternativeAddress: Person |
> +----------------------------+
>
> (the alternativeAddress not only contains city and street, but also
> names etc.)
>
> So, I've created a binding:
>
> IBeanValueProperty nameProperty = BeanProperties.value(Person.class,
> "name");
> IObservableValue<Person> model = nameProperty.observe(myEditor);
> uiWidget = WidgetProperties.text(SWT.Modify).observe(personEditorName);
> ctx.bindValue(uiWidget, model);
>
> This works for "name". But if I want to bind "alternativeAddress.name"
> nothing is stored. Do I have to write it in another way?
>
> TIA,
> Ralf.
Hi,
I found the solution for myself :-)
The problem was that the object for the nested property was created
*after* the binding. This doesn't work. You *always* have to bind editor
fields to an existing object (event if the fields are hidden).
So long,
Ralf.
|
|
|
Re: [Databinding/E4] Binding of nested properties [message #1740389 is a reply to message #1740310] |
Fri, 12 August 2016 07:32 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
On 11.08.16 15:09, Ralf Heydenreich wrote:
> Am 23.07.2016 um 02:05 schrieb Ralf Heydenreich:
>> Hi all,
>> I've an editor (MPart) which has a bound model. The model is, e.g., a
>> person with an address and an alternative address.
>>
>> Like so:
>>
>> +----------------------------+
>> | Person |
>> +----------------------------+
>> | name: String |
>> | surname: String |
>> | alternativeAddress: Person |
>> +----------------------------+
>>
>> (the alternativeAddress not only contains city and street, but also
>> names etc.)
>>
>> So, I've created a binding:
>>
>> IBeanValueProperty nameProperty = BeanProperties.value(Person.class,
>> "name");
>> IObservableValue<Person> model = nameProperty.observe(myEditor);
>> uiWidget = WidgetProperties.text(SWT.Modify).observe(personEditorName);
>> ctx.bindValue(uiWidget, model);
>>
>> This works for "name". But if I want to bind "alternativeAddress.name"
>> nothing is stored. Do I have to write it in another way?
>>
>> TIA,
>> Ralf.
>
>
> Hi,
> I found the solution for myself :-)
> The problem was that the object for the nested property was created
> *after* the binding. This doesn't work. You *always* have to bind editor
> fields to an existing object (event if the fields are hidden).
>
> So long,
> Ralf.
That's not 100% true. You could have used a master-observable and change
your code to
class MyEditorPart {
ObservableValue<Person> master = new WritableValue();
// ...
IObservableValue<Person> model = nameProperty.observeDetail(master);
}
This has the advantage that you don't have to rebind if you change the
person eg because another one was selected. I find myself using this
master everytime even if I currently don't change the master because it
gives me much more flexibility.
Tom
|
|
|
Powered by
FUDForum. Page generated in 0.04005 seconds