“onBeforeRendering” or “onAfterRendering” is not called every time the view is opened

Why (…) is the onBeforeRendering not triggered every time the view is displayed? I think there is a misconception of what “rendering” means. In UI5, when a control is “rendering”, its corresponding HTML element is being modified or created in the DOM by the RenderManager. I.e. onBeforeRendering means literally “before the render function of the … Read more

How to make use of navigation property?

Navigation properties are, as the name suggests, properties with which you can navigate to related entity types. The UI5 framework supports this feature too so that app developers don’t have to extract URLs by hand. In fact, you won’t even need to call read. Let’s take this entity data model for example: CustomerSet NavigationProperty: “ToOrders” … Read more

How to handle the itemPress of sap.m.Table?

This really seems to be a frequent issue people face when they use sap.m.ListBase related controls. Let me give you an overview on how to manage the events (and particularly activate them at all): The confusion could be related to the sap.m.ListMode of controls inheriting from sap.m.ListBase and the sap.m.ListType of items inheriting from sap.m.ListItemBase. … Read more

Property Binding: How to Concatenate String Literals and Binding Value

To enable complex binding syntax, the recommended way is to add the bootstrap configuration option compatVersion with the value “edge”. E.g. in index.html: data-sap-ui-compatversion=”edge” This replaces the need for sap-ui-xx-bindingSyntax since “edge” sets the binding syntax automatically to “complex”. Adding bindingSyntax makes only sense if the compatVersion is lower than “1.28”. Options with xx should … Read more

Difference Between this.getView().byId(), this.byId(), and sap.ui.getCore().byId()

Difference between this.getView().byId and this.byId Take a look at the source code of the this.byId method: // sap.ui.core.mvc.Controller Controller.prototype.byId = function(sId) { return this.oView ? this.oView.byId(sId) : undefined; }; As you can see, this.byId is just a shortcut for this.getView().byId. They both can be used to access controls defined in the view. E.g.: <!– Given … Read more

How to get model on onInit?

You can avoid setTimeout, as mentioned in this answer, by using the v2.ODataModel API metadataLoaded instead which returns a promise. The promise is fulfilled once the service metadata is loaded successfully. onInit: async function() { const oPayerModel = this.getOwnerComponent().getModel(“SalesInvoices”); try { await oPayerModel.metadataLoaded(true); const oServiceMetadata = oPayerModel.getServiceMetadata(); // NOT .getMetadata() // … } catch (oError) … Read more

What is the EventBus in SAPUI5 for?

EventBus in UI5 is a tool with which we can leverage publish-subscribe pattern in our app. How do we get EventBus? Currently, there are two APIs which return their own instance of EventBus: Globally: sap.ui.getCore().getEventBus(); for Standalone apps. Component apps and their container app where developers have control over both. Component-based: this.getOwnerComponent().getEventBus(); // this == … Read more

Live Update the Number of Items

Client-side Models If a client-side model such as JSONModel is used (i.e. assuming all the data are already available on the client) and if the target collection is an array, a simple expression binding is sufficient: title=”{= ${myJSONModel>/myProducts}.length}” Sample 1 (ClientModel): Updating count after deleting items from sap.m.Table Sample 2 (ClientModel): Updating count after filtering … Read more

How to create OData V2 entity path dynamically in UI5?

Create the path dynamically via the API createKey from the V2 ODataModel: const path = myODataV2Model.createKey(“/Products”, { // Key(s) and value(s) of that entity set “ProductID”: myVar1, // with the value 999 for example “AnotherKeyProperty”: “…”, }); myODataV2Model.update(path/*, …*/); Compared to concatenating strings for the path manually, createKey offers the following advantages: It outputs the … Read more