Skip to Content
0

How to pass dynamic data to sap.m.link sapui5

Jul 04, 2017 at 07:22 AM

320

avatar image

Hi All,

I have few doubts in using SAP.M.LINK.

Through my oData, I am passing multiple links/URLs to my front end. These links will be available under "Attachments" label.

I am getting the value of my 1st link as -

var Link1 = sItem.getBindingContext().getProperty("Link1");

and similary...

var Link2 = sItem.getBindingContext().getProperty("Link2"); and other links.

I tried using the below syntax, but it does not navigate to my URL(even when Link1 has correct value). When I hard coded, a URL in my HREF property, it got successfully navigated to that URL. I am not able to find an error in debug mode.

Please help me with what I am doing wrong.

Thanks

Meenakshi

capture.png (7.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Pavan Bhamidipati Jul 04, 2017 at 11:10 AM
0

Hi

Please find below the view definition. I guess in your case the model which your binidng is more important. I created and XML view

<mvc:View controllerName="mysap.ui5.demo.walk.controller.App" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
	xmlns="sap.m" xmlns:u="sap.ui.unified">
	<App>
		<pages>
			<Page title="{i18n>title}">
				<content>
					<!--<u:Currency value="2300.12" currency="INR" useSymbol="true" />-->
					<Text text="{ path: '/number', type: 'sap.ui.model.type.Currency', formatOptions: { showMeasure: false } }"/>
					<!--<Text text="Hello World"/>-->
					<Link id="Test" text="Link1" href="{path: '/link1'}"></Link>
					<Link id="Test2" text="Link2" href="{path: '/link2'}"></Link>
				</content>
			</Page>
		</pages>
	</App>
</mvc:View>

The controller definition is as follows

sap.ui.define([
	"sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel",
	"sap/ui/core/format/NumberFormat"
], function(Controller, JSONModel, NumberFormat) {
	"use strict";


	return Controller.extend("mysap.ui5.demo.walk.controller.App", {
		_data: {
			"number": ["9999.99"],
			"link1" : 'https://www.google.com',
			"link2" : 'https://www.aol.com'
		},


		onInit: function(evt) {
			var oModel = new JSONModel(this._data);
			this.getView().setModel(oModel);
			var oFmtSet =  NumberFormat.getCurrencyInstance();
			// var oLocale = oFmtSet.getCurrencyInstance();
		}
	});


});

Thanks,

Pavan

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

Hi Pavan,

Thanks for your reply. I tried to use the below code, but it did not work -

capture.png (8.3 kB)
0

Hi,

For me, it looks fine irrespective of the view type. As I mentioned earlier the model which you have bound to the view could be making the difference.

sap.ui.jsview("mysap.ui5.sandappSandApplication.view.Main", {
	getControllerName: function() {
		return "mysap.ui5.sandappSandApplication.controller.Main";
	},
	createContent: function(oController) {
		var oPage = new sap.m.Page({
			title: "{i18n>title}",
			content: [
				new sap.m.Link({
						id: "link1", // sap.ui.core.ID
						text: "Link1", // string
						href: "{path: '/link1'}" // sap.ui.core.URI 
					}
				),
				new sap.m.Link({
						id: "link2", // sap.ui.core.ID
						text: "Link2", // string
						href: "{path: '/link2'}" // sap.ui.core.URI 
					}
				)
			]
		});


		var app = new sap.m.App("myApp", {
			initialPage: "oPage"
		});
		app.addPage(oPage);
		return app;
	}
});
<br>

Here is the controller,

sap.ui.define([
	"sap/ui/core/mvc/Controller" , "sap/ui/model/json/JSONModel",
	"sap/ui/core/format/NumberFormat"
], function(Controller, JSONModel, NumberFormat) {
	"use strict";


	return Controller.extend("mysap.ui5.sandappSandApplication.controller.Main", {
	
		_data: {
			"number": ["9999.99"],
			"link1" : 'https://www.google.com',
			"link2" : 'https://www.aol.com'
		},


		onInit: function(evt) {
			var oModel = new JSONModel(this._data);
			this.getView().setModel(oModel);
			var oFmtSet =  NumberFormat.getCurrencyInstance();
			// var oLocale = oFmtSet.getCurrencyInstance();
		}


	});
});
<br>

Please find the screen shot below

Thanks, Pavan

1.jpg (14.9 kB)
0

This code is being called in my simple form. I guess it has something to do with it.

Not sure !

0

I dont know why it did not work. So i used window.open(Link1);

this is working in my case. Thanks a lot :)

1

thanks for providing the workaround

0
Mahi theja Jul 04, 2017 at 07:39 AM
0

Hi Meenakshi,

Can you try with 'Press' event in sap.m.Link..

https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.Link.html#event:press

I am not sure are you setting href value dynamically for the link.

Regards,

Mahi theja

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

This is because I don't have a fixed URL. It will vary depending on a document number.

0