0
votes

For a SAPUI5 app I created an OData service having an entity "Enquiries". The service itself works fine.

In order to build a first SAPUI5 app on top of that service, I took the Walkthrough to get the basics: https://sapui5.hana.ondemand.com/#/topic/2366345a94f64ec1a80f9d9ce50a59ef

Now if I replace the Northwind Service by my one service and binding it as model "enquiry", it all works fine except one thing. When clicking on an list item ("enquiry/>Enquiries"), it loads the details of that object through data binding correctly - but only once! When going back to master view and selecting another list item, it opens the detail view again, but still shows the details of the first list item clicked.

It seems like the detail view is not refreshed when a new URL/path is opened by clicking on a list item in the master view. But it works 100% in the Walkthrough example in my environment using the Northwind OData service.

Does anybody have a clue?

Some coding...

list view:

<mvc:View
controllerName="sap.ui.demo.wt.controller.InvoiceList"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<List
    class="sapUiResponsiveMargin"
    width="auto"
    items="{path : 'enquiry>/Enquiries'}">      
    <items>
        <ObjectListItem
            title="{enquiry>CompanyName}"
            type="Navigation"
            press="onPress">
        </ObjectListItem>
    </items>
</List>
</mvc:View>

list controller - fires event onPress when clicking on a list item:

[..]
onPress: function (oEvent) {
        var oItem = oEvent.getSource();
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.navTo("detail", {
            enquiryPath: oItem.getBindingContext("enquiry").getPath().substr(1)
        });
    } 
[..]

detail view:

<mvc:View
controllerName="sap.ui.demo.wt.controller.Detail"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page
    title="{i18n>detailPageTitle}">
    <ObjectHeader
        intro="{enquiry>EnquiryID}"/>
</Page>

detail controller - fires event on init:

onInit: function () {
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);
    },

    _onObjectMatched: function (oEvent) {
        this.getView().bindElement({
            path: "/" + oEvent.getParameter("arguments").enquiryPath,
            model: "enquiry"
        });
    }
1
I can't find anything wrong from the given code. Could you solve the problem by now?Boghyon Hoffmann
Otherwise, please provide more code with which we can reproduce the behavior.Boghyon Hoffmann
Have you tried calling this.getView().unbindElement("yourmodelname") before the bindElement statement in your details page ?Daniel Almeida

1 Answers

2
votes

After suffering with a similar problem for a while, I finally found the culprit - in the model settings in manifest.json, I changed the "defaultBindingMode" from "OneTime" to "OneWay".

    "models": {
         ...
         ...

        "": {
            "type": "sap.ui.model.odata.v2.ODataModel",
            "settings": {
                "defaultOperationMode": "Server",
                "defaultBindingMode": "OneWay",
                "defaultCountMode": "Request"
            },
            "dataSource": "yourdatasource",
            "preload": true
        }
   }