I tried to implement split app feature in my mobile application .But after navigating to the Detail2 page a "back" navigation button is put , which does not work when pressed .
I have placed my code below : (Revert back if you need more info on that)
view.js file (content) :
sap.ui.jsview("split_app.first_view", {
getControllerName : function() {
return "split_app.first_view";
},
createContent : function(oController) {
var olist1 = new sap.m.StandardListItem({
type: sap.m.ListType.Active,
title: "to detail 1",
tap: function(){
osplit.toDetail("detail1");
}
});
var olist2 = new sap.m.StandardListItem({
type: sap.m.ListType.Active,
title: "to detail 2",
tap: function(){
osplit.toDetail("detail2");
}
});
var otext = new sap.m.Label({
text: "first label",
});
var osplit = new sap.m.SplitApp("split");
var odetail1 = new sap.m.Page("detail1", {
title: "first details",
content: [
otext
]
});
var odetail2 = new sap.m.Page("detail2",{
title: "second Details",
showNavButton: true,
navButtonPress: function(){
osplit.toMaster("masterPage");
app.back();
},
content: [
new sap.m.Label({
text: "second label"
})
]
});
var omaster1 = new sap.m.Page("masterPage", {
title: "master page",
content:[
new sap.m.List({
items : [ olist1, olist2 ]
}) ]
});
osplit.addMasterPage(omaster1);
osplit.addDetailPage(odetail1).addDetailPage(odetail2);
osplit.setMode("ShowHideMode");
return new sap.m.Page({
title: "Title",
content: [
osplit
]
});
}
Assuming you want to navigate one step back in your Detail Area (right side) you can call the backDetail() function of your SplitApp Object when clicking on the back button (navButtonPress):
osplit.backDetail();
The same function works for back navigation in your Master Area (left side):
osplit.backMaster();
If you want to navigate back within your app object, make sure that there is a previous page you come from and all pages are known to the App object (probably in your index.html file):
I´ve just tested your code and it worked for me to navigate within the SplitApp using above mentioned functions as well as navigating back in the App with the following declaration (in your index or wherever you host the App object):
var app = new sap.m.App();
var init = sap.ui.view({
id : "idinit",
viewName : "stackovertest.init",
type : sap.ui.core.mvc.ViewType.JS
})
var page = sap.ui.view({
id : "idsplit_app1",
viewName : "stackovertest.split_app",
type : sap.ui.core.mvc.ViewType.JS
});
app.addPage(init);
app.addPage(page);
After coming from the init page you can use
app.back();
Hopefully this helps you.
Related
I am trying to develop an SAPUI5 app but I can't add a specific text before the value in a table column.
onInit : function() {
var oModel = new sap.ui.model.json.JSONModel('add json file ');
sap.ui.getCore().setModel(oModel,'products');
}
In the View I am creating a table and binding all records:
var oTable = new sap.m.Table("productsTable",{
inset: true,
columns: [
//image
new sap.m.Column({
hAlign: "Left",
width: "100px",
demandPopin: true,
popinDisplay: "Block",
minScreenWidth: sap.m.ScreenSize.Medium
}),
]
});
var oTemplate = new sap.m.ColumnListItem({
type: sap.m.ListType.Active,
cells: [
new sap.m.Text({
text: "Title :{products>description} ",
//visible :false,
}),
]
});
oTable.bindAggregation("items","products>App",oTemplate); // Here bind all record
return new sap.m.Page({
title: "App Name",
content: [oTable],
showNavButton: true,
navButtonPress: function() {
oController.navigation();
},
footer: new sap.m.Bar({
contentLeft: [
new sap.m.Text({text: "Smart",})
]
}),
});
My desired output is:
But it's displayed this way:
As #Qualiture said in the comment this looks like you need to enable the complex binding syntax.
You can do that by setting the binding syntax mode explicitly using
data-sap-ui-bindingSyntax="complex" or implicitly by specifying the compatibility version of 1.26 or edge: data-sap-ui-compatversion="edge".
Try add slash (/) caracter before the property.
Sample:
"Title :{products>/description} "
OR
Maybe your binding is incorrect, try this
...
text: { path: "{products>/description}", //with or without slash (/)
formatter: function(desc) {
return "Title" + desc;
}
}
...
I'm trying to add Page into IconTabFilter and i've got, but only the title is projected on the screen.
IconTab view :
createContent : function(oController) {
var oPage = new sap.m.Page({title: "IconTab",showHeader: false});
var oIconTab = new sap.m.IconTabBar ("idTabBar",{});
var itemBar1 = new sap.m.IconTabFilter({
key:"tab1",
icon:"sap-icon://database",
content:[ new sap.ui.view({id:"idTabIcon",viewName:"prova5.tabIcon1", type:sap.ui.core.mvc.ViewType.JS})
]
})
oIconTab.addItem(itemBar3);
oPage.addContent(oIconTab);
return oPage;
}
content of IconTabFilter view:
createContent : function(oController) {
var oPage = new sap.m.Page({
title: "Icon Tab Page 1",
showNavButton: true,
navButtonPress: oController.navButtonMethod
});
var obutton = new sap.m.Button({text: "hello"});
oPage.addContent(obutton);
return oPage;
}
any solution?
The problem appears when using sap.m.Page in your view as a return value in the createContent function. If the usage of sap.m.Page in your view is not necessary for your purpose try to return another control (e.g. sap.m.FlexBox). That solved the problem for me.
Try to Inspect Elements and find out div and in the
class ".sapMITBContent" add height in Pixel around 500px and you will get page visible.
How can I get index of pressed ColumnListItem? I want to get and pass to controller method.
View code:
var oTable = new sap.m.Table({
id: "Countries",
mode: sap.m.ListMode.None,
columns: [ new sap.m.Column({
width: "1em",
header: new sap.m.Label({
text: "Name"
})
})
]
});
var template = new sap.m.ColumnListItem({
id: "first_template",
type: "Navigation",
visible: true,
selected: true,
cells: [ new sap.m.Label({
text: "{name}"
})
],
press: [oController.pressListMethod]
});
oTable.bindItems("/eventos", template, null, null);
oPage.addContent(oTable);
Controller code:
pressListMethod: function(index){
var oData = sap.ui.getCore().getModel().getProperty("/eventos/"+index+"/name");
alert(oData);
}
You shouldn´t rely on the index since the index in the table can differ from the index in your model (e.g. due to filtering and sorting).
You can read the bindingContext of the pressed ListItem like this:
pressListMethod: function(event){
var bindingContext = event.getSource().getBindingContext();
}
The bindingContext is an artificial object containing the related model and a path of the object within the model.
You can then read properties of your object like this:
var name = bindingContext.getProperty("name");
To get the whole object you can do it like this:
var myObject = bindingContext.getObject();
To get exact value of product
SelectedRowContext.getObject('PRODUCT_ID')
To get Name of product
SelectedRowContext.getObject('NAME')
I am trying to create a Master - Detail page using OData servicea in SAPUI5. Everything works fine in the Master page. Meaning I'm able to populate the list with valid data from SAP backend using an OData URL.
Now what I want to achieve is, to call a second OData URL to fetch the detail values and populate that in the page.
My Master.controller.js
handleListSelect : function (evt) {
var context = evt.getParameter("listItem").getBindingContext();
this.nav.to("Detail", context);
console.log('evt.getSource: ' + evt.getSource());
console.log('evt.getBindingContext: ' + evt.getSource().getBindingContext());
}
Console Output gives
"evt.getSource: Element sap.m.List#Master--list" sap-ui-core.js line 80 > eval:31
"evt.getBindingContext: undefined"
I'm unable to populate values in the detail page from the second URL. Can anyone guide or help me on this?
My Compenent.js
createContent : function() {
// create root view
var oView = sap.ui.view({
id : "app",
viewName : "sap.ui.demo.myFiori.view.App",
type : "JS",
viewData : {
component : this
}
});
// Using OData model to connect against a real service
var url = "/MyFioriUI5/proxy/sap/opu/odata/sap/XXXXXX;mo/";
var oModel = new sap.ui.model.odata.ODataModel(url, true, "", "");
oView.setModel(oModel);
// set i18n model
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/messageBundle.properties"
});
oView.setModel(i18nModel, "i18n");
// set device model
var deviceModel = new sap.ui.model.json.JSONModel({
isPhone : jQuery.device.is.phone,
isNoPhone : !jQuery.device.is.phone,
listMode : (jQuery.device.is.phone) ? "None" : "SingleSelectMaster",
listItemType : (jQuery.device.is.phone) ? "Active" : "Inactive"
});
deviceModel.setDefaultBindingMode("OneWay");
oView.setModel(deviceModel, "device");
// Using a local model for offline development
// var oModel = new sap.ui.model.json.JSONModel("model/mock.json");
// oView.setModel(oModel);
// done
return oView;
}
My Detail.controller.js
sap.ui.controller("sap.ui.demo.myFiori.view.Detail", {
handleNavButtonPress : function(evt) {
this.nav.back("Master");
},
onBeforeRendering : function() {
// this.byId("SupplierForm").bindElement("BusinessPartner");
},
handleApprove : function(evt) {
// show confirmation dialog
var bundle = this.getView().getModel("i18n").getResourceBundle();
sap.m.MessageBox.confirm(bundle.getText("ApproveDialogMsg"), function(oAction) {
if (sap.m.MessageBox.Action.OK === oAction) {
// notify user
var successMsg = bundle.getText("ApproveDialogSuccessMsg");
sap.m.MessageToast.show(successMsg);
// TODO call proper service method and update model (not part of this session)
}
},
bundle.getText("ApproveDialogTitle"));
}
});
I can't see the second URL you are refering to, but we handle it this way.
In Component.js:
var oView = sap.ui.view({
id: "app",
viewName: "fom.test.app.view.App",
type: "JS",
viewData: { component : this }
});
var dataModel = new sap.ui.model.odata.ODataModel("/fom/fiori/odata/FOM/mobile_app_srv", true);
oView.setModel(dataModel);
This connects the master view to the data for all the list items.
In the App.controller.js we make use of the onNavigation function, defined in Detail.controller.js. That means when routing to the detail view, the onNavigation function is called before the view is set up.
App.controller.js:
to : function (pageId, context) {
var app = this.getView().app;
// load page on demand
var master = ("Master" === pageId);
if (app.getPage(pageId, master) === null) {
var page = sap.ui.view({
id : pageId,
viewName : "fom.test.app.view.view." + pageId,
type : "XML"
});
page.getController().nav = this;
app.addPage(page, master);
jQuery.sap.log.info("app controller > loaded page: " + pageId);
}
// show the page
app.to(pageId);
// set data context on the page
if (context) {
var page = app.getPage(pageId);
page.setBindingContext(context);
try{
var oController = page.getController();
oController.onNavigation(context);
}
catch(e){ }
}
},
Detail.controller.js:
onNavigation: function(context) {
this.getView().bindElement({
path: context.sPath,
parameters: {
select: "Id," +
"Lifnam," +
"Rmwwr," +
"Waers," +
"Sendedatum," +
"Workflowtyp," +
"Sktodat," +
"Stufe," +
"MonFrgstA," +
"Bukrs," +
"Belnr," +
"Gjahr," +
"EdcObject," +
"BstatTxt",
expand: "Positions"
}
});
},
The bindElements() function, connects the detail view to the results of another web service call, which fetches all attributes mentioned in select and the line items which are fetched with the expand.
Now your first webservice call is loading only the data relevant for the master view list, and the second one all the information of the selected list item.
When you use the newer routing functionality of UI5, you will need to find another place for the hook. I haven't built that in yet.
oView.setModel(oModel);
You have this statement twice - the one would override the other - you need to provide an alternate reference to the second instance:
e.g.
oView.setModel(oModel, "local")
I have a SAPUI5 application written in MVC
I have a view called oPage4:
var landscapePage = new sap.m.Page({
title : "Landscape Name",
showNavButton : true,
navButtonPress : [oController.back,oController],
footer : new sap.m.Bar({
id : 'landscapePage_footer',
contentMiddle : [
new sap.m.Button({
}),
new sap.m.Button({
})
]
}),
});
oLandscapePageTable = new sap.m.Table("landscape", {
inset : true,
visible : true,
getIncludeItemInSelection : true,
showNoData : false,
columns : [ new sap.m.Column({
styleClass : "name",
hAlign : "Left",
header : new sap.m.Label({
})
}) ]
});
landscapePage.addContent(oLandscapePageTable);
return landscapePage;
then inside page1 controller I want to add a columnlistitem to the table of page 4.
var oPage4 = sap.ui.getCore().byId("p4");
var landscapePageRow = new sap.m.ColumnListItem({
type : "Active",
visible : true,
selected : true,
cells : [ new sap.m.Label({
text : something
}) ]
});
oPage4.getContent().addItem(landscapePageRow);
it doesn't work. please show me how to do so?
Ok, I think I understood your problem now. In general I would avoid calling the page and doing manipulations on it from another view. However, it is absolutely possible:
Additional functions in your view
You can extend your page4 with some more functions that can be called from outside like this:
sap.ui.jsview("my.page4", {
createContent : function() {
this.table = ...
...
},
addColumnListItem : function(columnListItem) {
// add it to the table calling this.table ...
}
}
From another view you´re now able to call this function like this:
var page4 = sap.ui.jsview("my.page4");
page4.addColumnListItem(page4, columnListItem);
Attention: The page4 object itself doesn´t point to the control you´re returning but to the the view instance itself. You will notice this, if you log the page4 object to the console. This is why you have to add functions like described.
Some other approaches would be to use the EventBus like described here to publish and subscribe to events. Since you´ve asked for it let me show you how you could do it:
Using the EventBus
The main intention is, that one can subscribe to a particular event and others can publish such events to the eventbus. Let me give you an example:
Subscribing to the EventBus:
var eventBus = sap.ui.getCore().getEventBus();
eventBus.subscribe("channel1", "event1", this.handleEvent1, this);
Of course you can name your channel and events as you wish. The third parameter indicates the function, that will be called in case of published events. The last paramter is the scope 'this' will point to in the given function.
Your handleEvent1 function could look like this:
handleEvent1 : function(channel, event, data) {
var listItem = data.listItem
}
Publishing events to the EventBus:
var columnListItem = ...
var eventBus = sap.ui.getCore().getEventBus();
eventBus.publish("channel1", "event1",
{
listItem : columnListItem
}
);
One more option you have is to make the columnListItems depending on a model. Like everytime it depends on your actual architecture and data.
Let me know if this solved your problem or if you need some more information.