Abdul Qayyum
Abdul Qayyum

Reputation: 11

How to change Standard Application label text in UI5 dynamically in view controller

i am extending SAP standard HCM Application and standard field(STRAS) label coming from ODATA is 'House Number and Street' but i want to change and assign new label text 'Address Line 1' in UI5 View controller at runtime instead of copying standard ODATA and creating custom ODATA for this small change.

Note : Label is not bound through i18n Model in standard Application

<!-- Street / STRAS -->
<Label text="{/#Address10/Street/@sap:label}" id="lblStreet" labelFor="txtStreet" visible="{FieldStates>/STRAS/Visible}"/>
<Text id="txtStreet" text="{Street}" visible="{FieldStates>/STRAS/Visible}"/>

Any help would be highly appreciated.

Regards,

Upvotes: 1

Views: 2470

Answers (1)

Jorge Martins
Jorge Martins

Reputation: 321

You can try to implement a Controller Extension.

You just need to add the following code in your manifest.json file inside the "sap.ui5" object:

"extends": {
    "component": "Standard App Namespace",
    "extensions": {  
        "sap.ui.controllerExtensions": {
            "standard.namespace.controller.ControllerName": {
                "controllerName": "my.namespace.ControllerNameExt"
            }
        }
    }
}

Just replace the namespaces with the correct ones for your use case.

In the controller implementation you can add (check is page for details on creating the controller):

onInit: function() { 
   this.getView().byId("lblStreet").setText("my new label"); 
}

Upvotes: 0

Related Questions