sapui5, MessageToast.show is not a function, although sap/m/MessageToast has already been imported - sapui5

I would like to display a messager in sapui5 Application, when onSave is printed or at the init function ist started. but i have always a error in the console and the messageToast do not work.
Errormessage in console:
Uncaught (in promise) TypeError: MessageToast.show is not a function
this is my controller.js:
sap.ui.define(['sap/ui/core/mvc/Controller',
'timeTrackertimeTracker/controller/BaseController',
'sap/ui/model/json/JSONModel',
"sap/m/MessageToast",
"sap/ui/model/odata/ODataModel",
"sap/ui/core/routing/History"
],
function(Controller, BaseController, MessageToast, JSONModel, ODataModel, History) {
"use strict";
//Global variables
//var _oController, oModel, oView;
var Calendarcontroller = BaseController.extend("timeTrackertimeTracker.controller.Calendarform", {
/* =========================================================== */
/* lifecycle methods */
/* =========================================================== */
onInit: function() {
//Store controller reference to global variable
this.getRouter().getRoute("Calendarform").attachPatternMatched(this._onRouteMatched, this);
MessageToast.show("init");
},
/* =========================================================== */
/* event handlers */
/* =========================================================== */
_onRouteMatched: function() {
// register for metadata loaded events
var oModel = this.getModel("appointments");
oModel.metadataLoaded().then(this._onMetadataLoaded.bind(this));
},
_onMetadataLoaded: function () {
// create default properties
var oProperties = {
Id: "Id" + parseInt(Math.random() * 1000000000)
/* duration: "",
resttime: "",
title: "",
starttime: "",
endtime: "",
Description: ""*/
};
// create new entry in the model
this._oContext = this.getModel("appointments").createEntry("/appointments", {
properties: oProperties
,
success: this._onCreateSuccess.bind(this)
});
// bind the view to the new entry
this.getView().setBindingContext(this._oContext, "appointments");
},
onSave: function(oEvent) {
// bind the view to the new entry
//this.getView().setBindingContext(this._oContext);
this.getModel("appointments").submitChanges();
},
_onCreateSuccess: function (oEvent) {
// navigate to the new product's object view
this.getRouter().navTo("AppointmentsList", true);
// unbind the view to not show this object again
this.getView().unbindObject();
// show success messge
/* var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oEvent.Id ]);
MessageToast.show(sMessage, {
closeOnBrowserNavigation : false
});*/
},
/* _onCreateSuccess: function (oAppointment) {
// show success messge
var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oAppointment.Title ]);
MessageToast.show(sMessage, {
closeOnBrowserNavigation : false
});
},
*/
onCancel: function() {
this.onNavBack();
//this.getView().getModel("appointments").deleteCreatedEntry(this._oContext);
},
/**
* Event handler for navigating back.
* It checks if there is a history entry. If yes, history.go(-1) will happen.
* If not, it will replace the current entry of the browser history with the worklist route.
* #public
*/
onNavBack : function() {
/* var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("AppointmentsList");*/
var oHistory = History.getInstance(),
sPreviousHash = oHistory.getPreviousHash();
// discard new product from model.
this.getModel("appointments").deleteCreatedEntry(this._oContext);
if (sPreviousHash !== undefined) {
// The history contains a previous entry
history.go(-1);
} else {
// Otherwise we go backwards with a forward history
var bReplace = true;
this.getRouter().navTo("AppointmentsList", {}, bReplace);
}
}
});
return Calendarcontroller;
});

Exchange places of parameters MessageToast and JSONModel in function (line 9): in the dependency list sap/ui/model/json/JSONModel mentioned before sap/m/MessageToast

Related

Dialog is not a constructor ui5

I get an error while using an reusing a dialog in sapui5:
Dialog is not a constructor
I want to create a dialog fragment. dialog.js contains all functions and after that make it global in the component.js
sap.ui.define([
"sap/ui/base/Object"
], function (Object) {
"use strict";
return Object.extend("tmp.Zprojetyousra.controller.Dialog", {
constructor : function (oView) {
this._oView = oView;
},
open : function () {
var oView = this._oView;
var oDialog = oView.byId("dialog");
// create dialog lazily
if (!oDialog) {
var oFragmentController = {
onCloseDialog : function () {
oDialog.close();
}
};
// create dialog via fragment factory
oDialog = sap.ui.xmlfragment(oView.getId(), "tmp.Zprojetyousra.view.Dialog", oFragmentController);
// connect dialog to the root view of this component (models, lifecycle)
oView.addDependent(oDialog);
}
oDialog.open();
}
});
});
HTML:
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<Dialog
id="dialog"
title="Hello dialogs}">
<content>
<core:Icon
src="sap-icon://hello-world"
size="8rem"
class="sapUiMediumMargin"/>
</content>
<beginButton>
<Button
text="{i18n>dialogCloseButtonText}"
press="onCloseDialog"/>
</beginButton>
</Dialog>
</core:FragmentDefinition>
JS:
sap.ui.define([
"sap/ui/core/UIComponent",
/* "tmp/Zprojetyoussra/model/models", peut influencer sur le code */
"sap/ui/model/json/JSONModel",
"tmp/Zprojetyoussra/controller/Dialog" ,
"sap/ui/Device"
/// device toujours doit etre a la fin des dependecies
], function (UIComponent, JSONModel, Device, Dialog) {
"use strict";
return UIComponent.extend("tmp.Zprojetyoussra.Component", {
metadata: {
// rootView: "tmp.Zprojetyoussra.view.tesstview"
manifest: "json"
},
init: function () {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// set data model
var oData = {
recipient : {
name : "World"
}
};
// without this.getview
var oModel = new sap.ui.model.json.JSONModel(oData);
this.setModel(oModel);
// set i18n model
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleName : "tmp.Zprojetyoussra.i18n.i18n"
});
this.setModel(i18nModel, "i18n");
/* eslint-disable no-alert */
// debug code to show an alert for missing destination or CORS issues in the tutorial (see step 26 for details)
this.getModel("invoice").attachEventOnce("metadataFailed", function(oEvent) {
alert("Request to the OData remote service failed.\nRead the Walkthrough Tutorial Step 26 to understand why you don't see any data here.");
});
// set device model
var oDeviceModel = new JSONModel(Device);
oDeviceModel.setDefaultBindingMode("OneWay");
this.setModel(oDeviceModel, "device");
this._dialog= new Dialog();
// create the views based on the url/hash
this.getRouter().initialize();
}
});
});
Error:
You have a wrong order of your imports in the controller define section. In the array you have:
UIComponent, JSONModel, Dialog, Device
but in the function definition below you have:
UIComponent, JSONModel, Device, Dialog
So the Dialog variable holds Device namespace which doesn't have a controller.
As #vasek said put your import in the right order use this syntax in your js file :
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/model/json/JSONModel",
"tmp/Zprojetyoussra/controller/Dialog" ,
"sap/ui/Device"
], function (UIComponent, JSONModel, Dialog, Device) {
"use strict";
return UIComponent.extend("tmp.Zprojetyoussra.Component", {
metadata: {
// rootView: "tmp.Zprojetyoussra.view.tesstview"
manifest: "json"
},

SAPUI5 SmartTable pressItem event is triggered twice

I have the issue that the pressItem event is triggered twice at smarttable ( sapui5).
The smarttable has type ResponsiveTable.
onAfterRendering : function(){
var tTable = this.byId("LineItemsSmartTable");
var oTable = this.byId("LineItemsSmartTable").getTable();
oTable.setMode(sap.m.ListMode.SingleSelectMaster);
oTable.onAfterRendering = function(){
this.attachItemPress(function(oEvent){ alert( "Pressed" ); });
};
// var fnItemPress = function(){ alert("press2") };
tTable.attachDataReceived(function(){
var aItems = oTable.getItems();
if(aItems.length === 0 ) return;
$.each(aItems, function(oIndex, oItem) {
//oItem.detachPress(fnItemPress);
oItem.setType("Active");
// oItem.attachPress(fnItemPress);
});
});
}
If onAfterRendering is not being called already onInit then reconsider renaming the function oTable.onAfterRendering.
onAfterRendering is already called in the controller lifecycle, you could try creating a new function and then calling that in onAfterRendering.
See this answer
onAfterRendering: function() {
this.tableItems();
},
tableItems: function() {
var tTable = this.byId("LineItemsSmartTable");
var oTable = this.byId("LineItemsSmartTable").getTable();
oTable.setMode(sap.m.ListMode.SingleSelectMaster);
oTable.attachItemPress(function(oEvent) {
alert("Pressed");
});
tTable.attachDataReceived(function() {
var aItems = oTable.getItems();
if (aItems.length === 0) return;
$.each(aItems, function(oIndex, oItem) {
oItem.setType("Active");
});
});
}

Master Detail View [Binding not working] SAPUI5

Expected Output
On clicking a row of the table details page should show the details of that row
Issue
Data binding not working.
In details view the controls are not showing the data bind to it.
In details view controller, if I print the context(which i am getting through getSelectedContext() on table)in console it is showing the data, but in view the controls are not showing the data
bind to it
index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->
<script>
//set local resources
sap.ui.localResources("odatacruddemo");
//create app and set the initialPage to be displayed
var app = new sap.m.App({
initialPage: 'masterPage'
});
var masterPage = new sap.ui.view({
id: 'masterPage',
viewName: 'odatacruddemo.Master',
type: sap.ui.core.mvc.ViewType.JS
});
var detailsPage = new sap.ui.view({
id: 'detailsPage',
viewName: 'odatacruddemo.Details',
type: sap.ui.core.mvc.ViewType.JS
});
app.addPage(masterPage);
app.addPage(detailsPage);
app.placeAt('content');
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
Master.view.js
sap.ui.jsview("odatacruddemo.Master", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* #memberOf odatacruddemo.Master
*/
getControllerName : function() {
return "odatacruddemo.Master";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* #memberOf odatacruddemo.Master
*/
createContent : function(oController) {
//add columns in a array to be added in table
var aProductTableColumns = [
new sap.m.Column({
header: new sap.m.Text({
text: 'Person ID'
})
}),
new sap.m.Column({
header: new sap.m.Text({
text: 'Name'
})
}),
new sap.m.Column({
header: new sap.m.Text({
text: 'EmployeeID'
})
}),
new sap.m.Column({
header: new sap.m.Text({
text: 'HireDate'
})
}),
new sap.m.Column({
header: new sap.m.Text({
text: 'Salary'
})
}),
new sap.m.Column({
header: new sap.m.Text({
text: 'Operations'
})
})
];
//add the data to the table using cells aggregation by using ColumnListItem
var oTableTemplate = new sap.m.ColumnListItem({
type: "Navigation",
press: [oController.onListPress, oController],
cells: [
new sap.m.ObjectIdentifier({
text: '{ID}'
}),
new sap.m.ObjectIdentifier({
text: '{Name}'
}),
new sap.m.ObjectIdentifier({
text: '{EmployeeID}'
}),
new sap.m.ObjectIdentifier({
text: '{HireDate}'
}),
new sap.m.ObjectIdentifier({
text: '{Salary}',
})
]
}).addStyleClass("sapUiResponsiveMargin");
//oTableTemplate.setType(sap.m.ListType.Active);
//create dialog for updating/editing data
var editPersonDetailsDialog = new sap.m.Dialog({
id: 'editPersonDetailsDialog',
title: 'Update Details'
});
//create table
var oProductTable = new sap.m.Table({
id: 'oProductTable',
columns: aProductTableColumns,
itemPress: [oController.onListPress,oController]
});
//oProductTable.setMode(sap.m.ListMode.SingleSelect);
oProductTable.setMode(sap.m.ListMode.SingleSelectMaster);
//bind the JSON data received from the service with Table
oProductTable.bindItems("/value",oTableTemplate);
var masterPage = new sap.m.Page({
title: "CRUD Operations on Public Odata Service",
content: [
oProductTable
]
});
return masterPage;
}
});
Master.Controller.js
sap.ui.controller("odatacruddemo.Master", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* #memberOf odatacruddemo.Master
*/
onInit: function() {
var serviceURL = 'http://services.odata.org/V4/OData/OData.svc/Persons?$expand=PersonDetail';
var oModel = new sap.ui.model.json.JSONModel(serviceURL);
oModel.attachRequestCompleted(function(oEvent){
//bind a model to a view
var masterView = sap.ui.getCore().byId("masterPage");
masterView.setModel(oModel);
//sap.ui.getCore().setModel(oModel);
});
//sap.ui.getCore().setModel(oModel);
},
/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* #memberOf odatacruddemo.Master
*/
// onBeforeRendering: function() {
//
// },
/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* #memberOf odatacruddemo.Master
*/
// onAfterRendering: function() {
//
// },
/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* #memberOf odatacruddemo.Master
*/
// onExit: function() {
//
// }
onListPress: function(oEvent){
console.log('List Item pressed');
//Get the Selected Items
//get the row data which has been clicked
var clickedItem = sap.ui.getCore().byId('oProductTable').getSelectedItems();
var cells = clickedItem[0].getCells();
var contexts = sap.ui.getCore().byId("oProductTable").getSelectedContexts();
console.log('Master ctx:');
console.log(contexts);
var items = contexts.map(function(c) {
return c.getObject();
});
console.log(items[0]);
var detailsPage = app.getPage('detailsPage');
detailsPage.setBindingContext(contexts,"data");
app.to(detailsPage);
//var detailsView = sap.ui.getCore().byId("detailsPage");
//detailsView.getModel().setData(items[0]);
//var oContext = oEvent.getSource().getBindingContext();
//console.log(oEvent);
}
});
In above code I am setting the bindingContext to detailsPage and I am able to get that context in detailsPage but in the view it not showing the data.
Below is the DetailPage Code:
Details.view.js
sap.ui.jsview("odatacruddemo.Details", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* #memberOf odatacruddemo.Details
*/
getControllerName : function() {
return "odatacruddemo.Details";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* #memberOf odatacruddemo.Details
*/
createContent : function(oController) {
var oObjectHeader = new sap.m.ObjectHeader({
title: "{Name}",
attributes:[
new sap.m.ObjectAttribute({
text: "{Name}"
})
]
});
var detailsPage = new sap.m.Page({
title: "DetailsPage",
content: [
oObjectHeader
]
});
return detailsPage;
}
});
Details.controller.js
sap.ui.controller("odatacruddemo.Details", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* #memberOf odatacruddemo.Details
*/
onInit: function() {
console.log('onInit() detailPage called');
},
/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* #memberOf odatacruddemo.Details
*/
onBeforeRendering: function() {
var detailsPage = sap.ui.getCore().byId('detailsPage');
var context = detailsPage.getBindingContext("data");
console.log('ctx:=>');
console.log(context);
var items = context.map(function(c) {
return c.getObject();
});
console.log(items[0]);
},
/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* #memberOf odatacruddemo.Details
*/
// onAfterRendering: function() {
//
// },
/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* #memberOf odatacruddemo.Details
*/
// onExit: function() {
//
// }
});
In the details View the controls are not showing the data bind to it.
Please help ...
Thanks in Advance...
your tables and controls are not having any data binding at all. You have to bind the items aggregation of your table. When using JS Views take a look at this API https://sapui5.hana.ondemand.com/#/api/sap.m.ListBase/methods/bindItems of sap.m.Table.
First of all you should use XMLViews instead of JsViews.
For your binding problem take a look in the SAPUI5 developer. Take a look at this example from the developer guide and go through it.
https://sapui5.hana.ondemand.com/#/topic/97830de2d7314e93b5c1ee3878a17be9
sap.ui.controller("odatacruddemo.Details", {
onInit: function() {
console.log('onInit() detailPage called');
var oModel2 = new sap.ui.model.json.JSONModel();
var detailsPage = sap.ui.getCore().byId('detailsPage');
detailsPage.setModel(oModel2);
this.getView().addEventDelegate({
onBeforeShow : function(evt) {
var detailsPage = sap.ui.getCore().byId('detailsPage');
var context = detailsPage.getBindingContext("data");
console.log('ctx:=>');
console.log(context);
//sap.ui.getCore().getModel().setData(json);
var items = context.map(function(c) {
return c.getObject();
});
console.log(items[0]);
var dPage = sap.ui.getCore().byId('detailsPage');
dPage.getModel().setData(items[0]);
},
});
},
onNavPress: function(){
app.back();
}});

Fire BarcodeScannerButton after View loads

I have implemented a scanner button on my Fiori/UI5 application. I used sap.ndc.BarcodeScannerButton and created that button on the controller (I cannot seem to create the button on my view.xml).
Anyway, I need to fire this button after the view loads. I have a master-detail application. The scanner button is on the master view ofcourse.
First thing I did was call the button itself. But my first problem is that the button does not accept an id as a parameter. It tells me that app cannot accept duplicate id. So what I did was just look for the button id. I was able to locate it (e.g. _button9) but whenever I call it via sap.ui.getCore.byId() there are times that it returns "undefined." That's why I cannot call firePress();
Another problem I have is where to put this firePress() method. I tried to put it on method onAfterRendering() assuming that again due to the undefined button I cannot call the method firePress(). I have tried putting it on other methods like after the data has been successfully called by using method attachRequestCompleted. No luck.
Below is the code
/*
* Copyright (C) 2009-2014 SAP SE or an SAP affiliate company. All rights reserved
*/
jQuery.sap.require("sap.ca.scfld.md.controller.ScfldMasterController");
jQuery.sap.require("ui.s2p.srm.sc.create.util.Formatter");
jQuery.sap.require("sap.ndc.BarcodeScannerButton");
var counter = 0;
sap.ui.controller("ui.s2p.srm.sc.create.SRM_SC_CREExtension.view.S2Custom", {
onInit: function() {
sap.ca.scfld.md.controller.ScfldMasterController.prototype.onInit.call(this);
this.oBundle = this.oApplicationFacade.getResourceBundle();
this.isRoot = true;
this.oRouter.attachRouteMatched(function(e) {
if (e.getParameter("name") === "master" && !this.isRoot && Object.keys(e.getParameter("arguments")).length === 0) {
var d = sap.ui.core.routing.History.getInstance().getDirection("shoppingCartCheckout/" + this.tempCartId);
if (d === "Unknown") {
this.isRoot = true;
this._oControlStore.oMasterSearchField.clear()
} else {
if (this.getList() !== null) {
var i = this.getList().getSelectedItem();
if (i !== null) {
//alert("setListGo");
this.setListItem(i);
}
}
}
}
this.isRoot = (this.isRoot) ? false : this.isRoot;
}, this);
// alert(sap.ui.getCore().byId("productScanButton"));
this.onBarcodeScanning();
this.setEmptyCart(true);
this.showAllProducts(); //added by salduam to show all products
},
backToList: function() {
//alert("back");
},
getDefaultUserSettings: function(r) {
var o = function(D, R) {
this.tempCartId = D.results[0].TEMP_CART_ID;
if (!jQuery.device.is.phone) {
if (r) {
this.oRouter.navTo("noData", {
viewTitle: "DETAIL_TITLE",
languageKey: "NO_ITEMS_AVAILABLE"
}, true)
} else {
this.navToEmptyView()
}
}
};
var d = this.oApplicationFacade.getODataModel("getdefusrset");
d.read("DefaultUserSettings?ts=" + Date.now(), null, null, true, jQuery.proxy(o, this), jQuery.proxy(this.onRequestFailed, this))
},
applySearchPatternToListItem: function(i, f) {
if (f.substring(0, 1) === "#") {
var t = f.substr(1);
var d = i.getBindingContext().getProperty("Name").toLowerCase();
return d.indexOf(t) === 0
} else {
return sap.ca.scfld.md.controller.ScfldMasterController.prototype.applySearchPatternToListItem.call(null, i, f)
}
},
getHeaderFooterOptions: function() {
var o = {
sI18NMasterTitle: "MASTER_TITLE",
buttonList: []
};
return o
},
isBackendSearch: function() {
return true
},
//call startReadListData with parameter wildcard
showAllProducts: function(e) {
var startSearchText = "*";
this.startReadListData(startSearchText);
//alert("called");
},
applyBackendSearchPattern: function(f, b) {
//added by salduam
//if search field is blank, automatically call showAllProducts
if (f == "") {
this.showAllProducts()
};
if (f != "" && f != null) {
this.startReadListData(f)
} else {
this.setEmptyCart(false)
}
},
startReadListData: function(f) {
var o = function(D, r) {
var m = new sap.ui.model.json.JSONModel(D.results);
this.getView().setModel(m);
this.getList().destroyItems();
this.getList().bindAggregation("items", {
path: "/",
template: this.oTemplate.clone(),
filter: [],
sorter: null
});
this.registerMasterListBind(this.getList());
};
var e = encodeURIComponent(f);
//console.log("EEEE-----"+ e);
var d = this.oApplicationFacade.getODataModel();
//console.log(d);
d.read("CATALOG_ITEM?$filter=startswith(description,'" + e + "')&$top=20", null, null, true, jQuery.proxy(o, this), jQuery.proxy(this.onRequestFailed,
this));
},
setListItem: function(i) {
// alert("onClick");
var b = i.getBindingContext();
var m = b.oModel.oData[parseInt(b.sPath.split('/')[1])];
this.oRouter.navTo("detail", {
tempCartId: this.tempCartId,
contextPath: b.getPath().substr(1)
}, true);
var c = sap.ui.core.Component.getOwnerIdFor(this.oView);
var C = sap.ui.component(c);
C.oEventBus.publish("ui.s2p.srm.sc.create", "refreshDetail", {
data: m
});
},
setEmptyCart: function(r) {
var e = new sap.ui.model.json.JSONModel({
results: []
});
this.oRouter.navTo("noData", {
viewTitle: "DETAIL_TITLE",
languageKey: "NO_ITEMS_AVAILABLE"
}, true);
this.getView().setModel(e);
this.oTemplate = new sap.m.ObjectListItem({
type: "{device>/listItemType}",
title: "{matnr}",
press: jQuery.proxy(this._handleItemPress, this),
number: "{parts:[{path:'itm_price'},{path:'itm_currency'}],formatter:'ui.s2p.srm.sc.create.util.Formatter.formatPrice'}",
numberUnit: "{itm_currency}",
attributes: [new sap.m.ObjectAttribute({
text: "{description}"
})],
});
this.getList().bindAggregation("items", {
path: "/results",
template: this.oTemplate,
filter: [],
sorter: null,
});
this.registerMasterListBind(this.getList());
this.getDefaultUserSettings(r)
},
onRequestFailed: function(e) {
jQuery.sap.require("sap.ca.ui.message.message");
sap.ca.ui.message.showMessageBox({
type: sap.ca.ui.message.Type.ERROR,
message: e.message,
details: e.response.body
})
},
onExit: function() {},
onBarcodeScanning: function(oEvent) {
var productScanButton = new sap.ndc.BarcodeScannerButton({
provideFallback: "{/btnFallback}",
width: "100%",
scanSuccess: function(oEvent) {
var barcodeID = oEvent.getParameter("text");
sap.m.MessageToast.show(barcodeID);
var searchField = sap.ui.getCore().byId("__field3");
searchField.setValue(barcodeID);
searchField.fireSearch();
}
});
this.getView().byId("barCodeVBox").addItem(productScanButton);
},
onAfterRendering: function(oEvent) {},
onBeforeRendering: function() {}
});
For placing the fire() method. Are you trying to display a pop-up barcode reader? something similar to the pop-up of the app "SD_SO_CRE" (where customer selection dialog is load before master view).
they do not solve the task with fire()...

hash format error! using routing

I have developed an OpenUI5 app ant it works fine!
But every time that I invoke the routing I have this message:
2015-07-15 16:15:45 hash format error! The current Hash: /line/01 -
log
error
onHashChange
detectHashChange
jQuery.event.dispatch
jQuery.event.add.elemData.handle
It is not a blocking problem but it is annoying because it dirty and fills thi debug console..!
To call the router I write:
this.router = sap.ui.core.UIComponent.getRouterFor(this);
this.router.navTo("activities", {
"id_line": '01'
});
and this is the routing file:
routes: [
...
{
pattern: "line/{id_line}",
name: "activities",
target: ["master_search", "detail_activities"]
},
...
],
targets: {
master_search: {
viewName: "UniversalMenu",
viewLevel: 1,
controlAggregation: "masterPages"
}
,
detail_activities: {
viewName: "DetailActivity",
viewLevel: 4
}
...
}
Edit: this is a snippet where I use jQuery.sap.history
jQuery.sap.require("jquery.sap.history");
jQuery.sap.require("sap.m.InstanceManager");
sap.ui.controller("ui5bp.view.App", {
getDefaultPage : function () {
return "Menu";
},
onInit : function () {
var historyDefaultHandler = function (navType) {
if (navType === jQuery.sap.history.NavType.Back) {
//this.navBack(this.getDefaultPage());
} else {
this.navTo(this.getDefaultPage(), null, false);
}
};
var historyPageHandler = function (params, navType) {
if (!params || !params.id) {
jQuery.sap.log.error("invalid parameter: " + params);
} else {
if (navType === jQuery.sap.history.NavType.Back) {
this.navBack(params.id);
} else {
this.navTo(params.id, params.data, false);
}
}
};
jQuery.sap.history({
routes: [{
// This handler is executed when you navigate back to the history state on the path "page"
path : "page",
handler : jQuery.proxy(historyPageHandler, this)
}],
// The default handler is executed when you navigate back to the history state with an empty hash
defaultHandler: jQuery.proxy(historyDefaultHandler, this)
});
// subscribe to event bus
var bus = sap.ui.getCore().getEventBus();
bus.subscribe("nav", "to", this.navHandler, this);
bus.subscribe("nav", "back", this.navHandler, this);
bus.subscribe("nav", "virtual", this.navHandler, this);
},
navHandler: function (channelId, eventId, data) {
if (eventId === "to") {
this.navTo(data.id, data.data, true);
} else if (eventId === "back") {
//**************************************************
// if(data && data.id){
// this.navBack(data.id);
// } else {
// jQuery.sap.history.back();
// }
var app = this.getView().app;
if(data.type==="master"){
app.backMaster();
}else if(data.type==="detail"){
app.backDetail();
}else{alert("back to master o detail?");};
//**************************************************
} else if (eventId === "virtual") {
jQuery.sap.history.addVirtualHistory();
} else {
jQuery.sap.log.error("'nav' event cannot be processed. There's no handler registered for event with id: " + eventId);
}
},
navTo : function (id, data, writeHistory) {
if (id === undefined) {
// invalid parameter
jQuery.sap.log.error("navTo failed due to missing id");
} else {
var app = this.getView().app;
// navigate in the app control
app.to(id, "slide", data);
}
},
/*
navBack : function (id) {
if (!id) {
// invalid parameter
jQuery.sap.log.error("navBack - parameters id must be given");
} else {
// close open popovers
if (sap.m.InstanceManager.hasOpenPopover()) {
sap.m.InstanceManager.closeAllPopovers();
}
// close open dialogs
if (sap.m.InstanceManager.hasOpenDialog()) {
sap.m.InstanceManager.closeAllDialogs();
jQuery.sap.log.info("navBack - closed dialog(s)");
}
// ... and navigate back
var app = this.getView().app;
var currentId = (app.getCurrentPage()) ? app.getCurrentPage().getId() : null;
if (currentId !== id) {
app.backToPage(id);
jQuery.sap.log.info("navBack - back to page: " + id);
}
}
}
*/
});
In Component.js I had 2 rows where I set up custom myNavBack and myNavToWithoutHash functions:
// 3a. monkey patch the router
var oRouter = this.getRouter();
oRouter.myNavBack = ui5bp.MyRouter.myNavBack; //to comment
oRouter.myNavToWithoutHash = ui5bp.MyRouter.myNavToWithoutHash; //to comment
I have started from an example of app skeleton for my app and then I have implemented the routing with the logic suggested from the framework.
This coexistence of two different methods to navigate produced the error in console. Tahnkyou #TimGerlach
After the comment of the two rows errors have vanished.