cancel
Showing results for 
Search instead for 
Did you mean: 

I can not access to _bindView and load view with data.

fjcvsap
Participant
0 Kudos

Hello,

I try to load data into the view and I can not do it.

When I am doing the debbug, my code never pass through this._bindView in _onObjectMatched, but I can get the value of sUser. Any help, thank you very much.

My view

<Button text="{User}" type="Transparent" press="handleUserNamePress">
					<layoutData>
						<OverflowToolbarLayoutData priority="NeverOverflow" />
					</layoutData>
				</Button>

My BaseController.js:

	getRouter: function () {
			return sap.ui.core.UIComponent.getRouterFor(this);
		},


		/**
		 * Convenience method for getting the view model by name.
		 * @public
		 * @param {string} [sName] the model name
		 * @returns {sap.ui.model.Model} the model instance
		 */
		getModel: function (sName) {
			return this.getView().getModel(sName);
		},


		/**
		 * Convenience method for setting the view model.
		 * @public
		 * @param {sap.ui.model.Model} oModel the model instance
		 * @param {string} sName the model name
		 * @returns {sap.ui.mvc.View} the view instance
		 */
		setModel: function (oModel, sName) {
			return this.getView().setModel(oModel, sName);
		},


		/**
		 * Getter for the resource bundle.
		 * @public
		 * @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
		 */
		getResourceBundle: function () {
			return this.getOwnerComponent().getModel("i18n").getResourceBundle();
		},

In my First.controller.js

_onObjectMatched: function (oEvent) {
			var sUser = JSON.parse(oEvent.getParameter("arguments").user);
		
		    this.getModel().metadataLoaded().then(function () {
				var sUserPath = this.getModel().createKey("UserSet", {
					User: sUser.nameUser, 
					descriptionName: sUser.descriptionName
				});
				this._bindView("/" + sUserPath);
			}.bind(this));
		},
	_bindView: function (sMainPath) {
			var oViewModel = this.getModel("First"),
				oDataModel = this.getModel();


			this.getView().bindElement({
				path: sMainPath,
				parameters: {
					expand: "ToSupplier"
				},
				events: {
					change: this._onBindingChange.bind(this),
					dataRequested: function () {
						oDataModel.metadataLoaded().then(function () {
							// Busy indicator on view should only be set if metadata is loaded,
							// otherwise there may be two busy indications next to each other on the
							// screen. This happens because route matched handler already calls '_bindView'
							// while metadata is loaded.
							oViewModel.setProperty("/busy", true);
						});
					},
					dataReceived: function () {
						oViewModel.setProperty("/busy", false);
					}
				}
			});
		},

Fabrice
Active Participant
0 Kudos

Hi,

do you have an error in the debugger console?

Regards,

Fabrice

Accepted Solutions (0)

Answers (2)

Answers (2)

maheshpalavalli
Active Contributor
0 Kudos

Hi PJ CV,

Taking your code as example,

1. metadataLoaded() method will return you the promise and you will use that promise and call your bind view in the success callback promise.then(...) . This will make sure that once the metadata of the odata service is loaded then only the bindview method is called. this is because in the bindview, you are calling bindElement which will call the odata service internally and odata metatadata should be loaded before calling the bindElement else an error will come. So we will wait till the metadata is loaded.

2. bindObject or bindElement(internally will call bindObject) is used to bind an object(Single entry out of an array of data) to a control. For more information see the documentation below:

https://ui5.sap.com/#/topic/91f05e8b6f4d1014b6dd926db0e91070

3. createKey is part of odata v2 model in your case

https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/createKey

If you pass the entity set and all the key names, It will give you the path for that object.

Eg.., If you want to do the elementBinding, you need to pass path

"/UserSet( User = 'TEST', descriptionName = 'Test User' )

If you want to create that above text you need to concatenate manually all the data and create the path. But if you call the createKey, it will return you the path. So simple right!!.

By the way, I think you have created descriptionName as the Key field, which is not required. Logically only "User" as the key field is enough. 🙂

As you are new to UI5, go through the walkthrough section of UI5 SDk atleast twice you will give more than enough information to create UI5 apps effortlessly :).

BR,

Mahesh

former_member601012
Discoverer
0 Kudos

The error in the debugger is :

[ODataMetadata] initial loading of metadata failed. So I am understood that I need to setup correctly the destination ... I think I need to learn more about bindElement, metadataLoaded and createKey.I would like also to know, why If the view is loaded I do not see in the source from the console the FirstController.js?

Thank you very much.

maheshpalavalli
Active Contributor
0 Kudos

Source information in the console..? you can see the source information in the sources right?