cancel
Showing results for 
Search instead for 
Did you mean: 

resourceBundle Error - SAP UI5

praveen_kumar194
Active Contributor
0 Kudos

Dear Team,

I am following tutorial using business application studio and facing this below error. i tried to search the forum. got few threads however did not help me to resolve the issue.

no matter which method i tried, i keep getting syntax error saying 'getResourceBundle' is not part of model. I am sending "sap/ui/model/resource/ResourceModel" module. then i am setting the resourcemodel like below.

var rmodel = new ResourceModel( {
bundleName : "My.Learning.webmodule.i18n.i18n" } );

this.getView().setModel(rmodel,"i18n");

after that i am trying to read the resource bundle with below syntax.

var oBundle = this.getView().getModel("i18n").getResourceBundle();

after getModel("i18n"), after pressing dot, even context help is not showing the getResourceBundle method. Below is the full source code.

am I missing something ? Please help.

sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/model/resource/ResourceModel" ], /** * @param{typeof sap.ui.core.mvc.Controller}Controller */ function (Controller,ResourceModel) { "use strict";
return Controller.extend("My.Learning.webmodule.controller.View", { onInit: function () {
var rmodel = new ResourceModel( {
bundleName : "My.Learning.webmodule.i18n.i18n" } );
this.getView().setModel(rmodel,"i18n");
}, onClick : function() { var oBundle = this.getView().getModel("i18n").getResourceBundle();
} }); });;
View Entire Topic
praveen_kumar194
Active Contributor
0 Kudos

just want to add one more question.

when i looked at syntax

this.getView().getModel() , getModel() will return sap.ui.model.Model. when i checked this class documentation does not hold getResourceBundle method. So how it is working for you. Please help. i am newbie here.

prashil
Advisor
Advisor
0 Kudos

Hi Praveen,

sap.ui.model.Model is the parent class, but while returning it will cast your return object based on the model type. If it oDataModel it will return oDataModel object and henceforth. In this case, the object returned is of sap.ui.model.resource.ResourceModel which has this method.

Thanks

Prashil