Skip to Content
0

Transfer Values Between two SAP UI5 Views

Nov 23, 2017 at 01:45 AM

44

avatar image

Hello:

I used the example at the following link to try to set, and then read, a model in the Core.

The code in the First (sending) Controller is:

onAddPressed: function(oEvent) {
	var oCustomerID = this.getView().byId("CustomerID").getText();
	var modelParameters = {};
	modelParameters.CustomerID = oCustomerID;
	this.customer.setData(modelParameters);
			
	sap.ui.getCore().setModel(this.customer);			
	var oBindingContext = oEvent.getSource().getBindingContext();
	var oCustomerModel = sap.ui.getCore().getModel('/CustomerID');
	},
onInit: function() {
	this.customer = new sap.ui.model.json.JSONModel();
	this.mBindingOptions = {};
	this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
	this.oRouter.getTarget("Customer").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
}

And in the Second (receiving) Controller is:

onAddPressed: function(oEvent) {
	var oCustomerNumber = sap.ui.getCore().getModel("/CustomerID");
}

When I stop on the first line in the receiving Controller, oCustomerNumber is undefined.

Am I forgetting to do something?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Irfan Gokak Nov 23, 2017 at 07:36 AM
1

Hi,

In First controller set value like this.

ap.ui.getCore().setModel(this.customer, "MdlName");

At receiving controller like this.

sap.ui.getCore().getModel("MdlName");

Try this

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks, was missing the model name...

0
tisha dharod Nov 23, 2017 at 11:35 AM
1

Hi Ian ,

Write below code in second controller . This would return all the data that you want in this controller

var oCustomerNumber = sap.ui.getCore().getModel( );
 var aData = oCustomerNumber.getData();
Show 1 Share
10 |10000 characters needed characters left characters exceeded

This got the value, thanks...

0
Jakob Marius Kjær Nov 23, 2017 at 12:27 PM
1

You shouldn't really set data in the core. Why don't you use routing?

Have a look here at this sample

Show 1 Share
10 |10000 characters needed characters left characters exceeded

It isn't my preference, but seem to be an expedient way to accomplish what I needed (passing a value from one view to another). If I read the code in the sample correctly, you can pass parameters when routing, is that true? (I am new to SAP UI5). I will try to find some additional tutorials, but that seems like a good approach, too!

0
Tri Minh Le Nov 23, 2017 at 05:00 AM
0

Hello Ian,

Are you sure this line works? Have you checked the returning value?

var oCustomerID = this.getView().byId("CustomerID").getText();

I assume that the element assigned by CustomerID is sap.ui.commons.TextField. Hence, you should change your code to

var oCustomerID = this.getView().byId("CustomerID").getValue();

Regards,

Tri

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I will correct that, also. Thanks, Tri!

Edit; turns out that 'CustomerID' is a (hidden) label, so getValue() doesn't work.

0