openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Feature Request: Add support for Binding Static Values to the UI

Open liwde opened this issue 8 years ago • 3 comments

In my project, I have a formatter handling some more complex translation logic. I want to use that formatter at the UI, but since the values I want to pass to the translator are static in the View, I can't provide them through a Model (which I could bind against).

From my perspective, the following syntax would be perfect:

<Label text="{value:'idSomething', formatter: '.translate'}" />

It would be event better, if the value could be a more complex thing like a JSON. This would also allow using static values in a multi-part binding:

<Dialog title="{parts: [
  {value: 'idTitle'}, {path: 'model>/SomeProperty'}
], formatter: '.translate'}" />

The only workaround I came across seems very unelegant to me: Create a JSON-Model where you manually put all the stuff:

this.getView().setModel(new JSONModel({
  'idSomething': 'idSomething'
  ...
}), 'static');
<Label text="{path:'static>/idSomething', formatter: '.translate'}" />

If I have to do this, falling back to just setting the text programmatically is the more maintainable solution, but I would end up having View-Code in the Controller and lose the declarative style I use XML-Views for in the first place.

As a first step, to me it seems very easy to have this implemented as a very limited Model-Type having just a very limited PropertyBinding to have a default Model 'static' at the UI that outputs just the Binding-Path as value -- this would look a lot like the last code-example just without having to manually create the ugly JSONModel.

Thank you very much for your help!

liwde avatar Aug 06 '18 09:08 liwde

Hello @liwde, Thank you for sharing your enhancement proposal. I've created an internal incident 1880532562. The status of the issue will be updated here in GitHub. Regards, Alex

JumpNRun avatar Aug 15 '18 08:08 JumpNRun

https://github.com/SAP/openui5/commit/c7b953e85eed283fd6cac90323bfaf59e3388410 by @goligo introduces static binding concept. You can try it out in https://jsbin.com/yeguhow/edit?js,output.

boghyon avatar Dec 04 '18 08:12 boghyon

This looks really nice! Thank you for implementing this feature, I'm really looking forward to using it!

liwde avatar Dec 04 '18 10:12 liwde