Search code examples
xmlmodelsapui5two-way-binding

TwoWay Binding to XMLModel with button Custom Data property not updating model


I have a very big problem updating the values of the sap.ui.model.xml.XMLModel.

It is made of TwoWay binding to the XMLModel and Custom Data of the Button control.
Updating the Custom Data value in JS code does not update the XMLModel, and thus the button description, priority of List Item, etc. do not change. I have no idea anymore, so please help

Part of JS code where I update Custom Data (This is method called by button) - and this works:

oEvent.getSource().data("Przeczytane", "true");

XML View:

<List items="{InfoNotif>/soap-env:Body/n0:ReadAdminMessageResponse/Dane/ListaKomunikatowAdministratora/KomunikatAdministratora}">
  <NotificationListItem
    title="{InfoNotif>Tytul/text()}"
    description="{InfoNotif>Opis/text()}"
    showCloseButton="false"
    datetime="{InfoNotif>DataPublikacji/text()}"
    unread="false"
    close=".onItemClose"
    authorName="{InfoNotif>IdUzytkownikaSystemu/text()}"
    authorPicture="sap-icon://group"
    priority="{=${InfoNotif>Przeczytano/text()}==='true' ? 'None' : 'High'}"
  >
    <buttons>
      <Button
        text="{=${InfoNotif>Przeczytano/text()}==='true' ? 'Oznacz jako nieprzeczytane' : 'Oznacz jako przeczytane'}"
        type="Accept"
        app:IdKomunikatuAdmin="{InfoNotif>IdKomunikatu/text()}"
        app:IdProcesuAdmin="{InfoNotif>/****/IdKomunikatu/text()}"
        app:Przeczytane="{
          path: 'InfoNotif>Przeczytano',
          mode: 'sap.ui.model.BindingMode.TwoWay',
          type: 'sap.ui.model.type.String'
        }"
        press=".onAcceptInfoPress"
      />
    </buttons>
  </NotificationListItem>
</List>

Result is:

  • Custom Data new value set correct
  • value in XMLModel NOT SET
  • other controls binding to /Przeczytano/text() not updated

Solution

  • I haven't worked with an XMLModel before but I tried to create a small sample.

    Just modify the Input in the first column or press the Button in the second column to see the effect.

    It seems like two way binding works (better) if you remove the text() statement (and then it also looks more like the other models, making it easier to replace it with JSON/OData).

    Then I extended the sample to see if the model can be modified in JS code. And (just like with regular models) it works best if you modify the model using setProperty and don't try to modify the controls directly.

    If you use oBindingContext.getObject(...) to access a property you have to add text() to the path (oContext.getObject("text1/text()")) or read the textContent from the result (oContext.getObject("text1").textContent). This also makes it harder to replace it with a JSON/ODataModel so I used oModel.getProperty(...) instead.