Skip to Content
0

Help ! Please i want see the detail in another view.

Apr 22 at 11:48 AM

65

avatar image
Former Member
Hello everyone,

I would like to see the detail of my airports in another view, I followed the tutorial of: https://sapui5.hana.ondemand.com/sdk/#/topic/2366345a94f64ec1a80f9d9ce50a59ef.html

but I have an error: Error: Invalid value "products / 1" for segment "{airportPath}".

Can someone help me,  please?

thank you

<br>
Airport.controller.js

onInit: function() {
var oList = this.getView().byId("List01");


oList.bindItems({
	path: "JSON>/products",
	template: new sap.m.StandardListItem({
		type : "Navigation",
		title: "{JSON>fields/aeroport}",
		press:[this.onPress ,this]
				})
			});
		
		},
		
onPress : function (oEvt){
var oItem = oEvt.getSource();
var temp = oItem.getBindingContext("JSON").getPath().substr(1);
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("Detail", {
airportPath : temp
			});
		},
		
		
 >>>detailAirport.controller.js



	

onInit: function() {
				
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);				
			},
			
_onObjectMatched : function(oEvt){
				
this.getView().bindElement({
path: "/" + oEvt.getParameter("arguments").airportPath,
model: "JSON"
				});	
			},
manifest.json	

"routes": [
				{
					"pattern": "",
					"name": "Principal",
					"target": [
						"Principal"
						]
				
				},{
					"pattern": "CdgInformation/",
					"name": "CdgInformation",
					"target": [
						"CdgInformation"
						]
				
				},{
					"pattern": "FlightChart/",
					"name": "FlightChart",
					"target": [
						"FlightChart"
						]
				},{
					"pattern": "OtherAirport/",
					"name": "OtherAirport",
					"target": [
						"OtherAirport"
						]
				},{
HERE	>>>>>>>>>		    "pattern": "Detail/{airportPath}",
					"name": "Detail",
					"target": [
						"Detail"
						]
				}
				],
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Thales Batista Apr 22 at 03:53 PM
0

Hi Mathieu,

Reading this code and error message, you temp variable contains "products/1". From the tutorial link you provided, it mentions:

We need to remove the first / from the binding path by calling .substr(1) on the string because this is a special character in URLs and is not allowed, we will add it again on the detail page.

The character "/" can't be in any position from navigation parameter. Technically you should provide the only the ID in the route parameter and build additional prefix (if required) on the Detail binding (i.e. you should only provide "1", your airport ID, to navTo method).

You can simply pass a higher number to substr to get only the ID (in this case 9) but normally you get the ID from object with getProperty method from binding context. Please check the Navigation and Routing - Step 7 - Navigate to Routes with Mandatory Parameters code from UI5 samples, both EmployeeList and Employee controllers.

Regards.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 22 at 04:18 PM
0

Hi Thales !

I understand and I fix it ... and .. yes it works :) !

Thanks a lot !

Share
10 |10000 characters needed characters left characters exceeded