SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.95k stars 1.24k forks source link

Enhancement request: Get value of control's property inside expression binding #1072

Open boghyon opened 8 years ago

boghyon commented 8 years ago

Hi,

When I'm defining a new control inside an XML-View , I'd like to be able to use the reference to that control and use the value of its certain property inside the expression binding.

Something like this: ... property="{= thisControl.valueState === 'Error' ? _doThis_ : _doThat_ }" ...

Of course, I could just define an extra JSONModel and store the controls properties there in order to use it later in the expression binding, but that concept doesn't work when I'm working with aggregation binding.

TobiasOetzel commented 8 years ago

Hi boghyon,

Just a check if i understand the enhancement correctly: I put up this scenario: <Input value="{= thisControl.getValueState() === 'Error' ? 'Wrong' : 'All good' } valueState="Error" />"

Here are my Questions

  1. is thisControl the Input?
  2. When the property 'valueState' changes is the property 'value' is changed?
  3. thisControl.valueState is a field did you mean the getter?

If this is the desired feature, it is probably a big change because the current change detection of bindings is currently only triggered by model Data. Control setters are not inside of the change detection. So i don't know if this enhancement will be done.

When you answered my 2 Questions i will forward it to the responsible developer.

a Note to the local JSON model: probably thisControl.valueState is probably also bound to a value of the model. Then you could repeat the binding inside of the valueState. But i totally agree that it is very ugly to spread a lot of complicated bindings across the VIews so JSON model is probably the way to go.

Best regards, Tobias

boghyon commented 8 years ago

Hi Tobias,

Sorry for the lack of information. Yes, you are correct. In this example, "thisControl" is the Input. When its property "valueState" changes, its "value" property should also be notified and change its value accordingly. For the third question, I cannot give a definite answer. It doesn't have to be a getter or a field, since my example code was just a concept (it could be however it's easy for the responsible developers to implement this feature).

I understand that it would be a big change. I just hope that there is an easier way to get desired control's properties inside an expression binding (or forward that control's instance to a formatter) so that we don't have to rely on JSON models.

TobiasOetzel commented 8 years ago

Hi boghyon,

i have forwarded it to the responsible developer and he will get back to you.

Best regards, Tobias

monavari-lebrecht commented 8 years ago

Isn't this very similar to the Pull Request https://github.com/SAP/openui5/pull/727 ?

ThomasChadzelek commented 8 years ago

Yes, I agree. Your pull request provides an answer to Boghyon's question.

As I already commented, your suggestion is a general "enhancement to basic binding concepts which of course can be used inside expression binding, but not only there". This is a good thing! But it means the tests are misplaced and we need other people's approval as well, not just mine.

I like the idea of binding to another (or the own) control's properties via a syntax similar to "model>path". But: "@" is not a reserved character within a model name, e.g. "@i18n" is a perfectly valid model name as of today. I fear this change is somewhat incompatible. We need to find a better syntax.