
// create a new Application state (oAppState) for this Application instance
oAppState = sap.ushell.Container
.getService("CrossApplicationNavigation")
.createEmptyAppState(this);
oAppState.setData(oStateToSave); // object of values needed to be restored
oAppState.save();
var oHashChanger = sap.ui.core.routing.HashChanger.getInstance();
var sOldHash = oHashChanger.getHash();
var sNewHash = sOldHash + "?" + "sap-iapp-state=" + this.oAppState.getKey();
oHashChanger.replaceHash(sNewHash);
sap.ushell.Container
.getService("CrossApplicationNavigation")
.toExternal({
target: {
semanticObject: sSemanticObject,
action: sAction
},
params: oParams,
appStateKey : oAppState.getKey()
});
var sHash = oHashChanger.getHash()
var sAppStateKey = /(?:sap-iapp-state=)([^&=]+)/.exec(sHash)[1];
sap.ushell.Container
.getService("CrossApplicationNavigation")
.getAppState(sAppStateKey)
.done(function (oSavedAppState) {
<< code for restoring app state >>
});
sap.ui.define([
..
"sap/ui/generic/app/navigation/service/NavigationHandler",
"sap/ui/generic/app/navigation/service/NavType"
], function(.. NavigationHandler, NavType) {
onInit: function() {
..
// create an instance of the navigation handler
this.oNavigationHandler = new NavigationHandler(this);
// on back navigation, the previous app state is returned in a Promise
this.oNavigationHandler
.parseNavigation()
.done(this.onNavigationDone.bind(this));
// the app state which needs persisting
this._oAppState = {
selectedTabFilter: "all",
searchText: "",
selectedContextPaths: [],
selectedCategories: [],
selectedSuppliers: []
};
onPress: function(oEvent) {
.
//(sSemanticObject, sActionName, vParameters?, oAppData?, fnError?)
this.oNavigationHandler
.navigate("Navigation", "sample",{},{ customData: this._oAppState });
/**
* if navigated back with appstate enabled then rehydrate the page using the
* stored data
* @param {Object} oAppData data persisted via iAppState
* @param {Object} oURLParameters paramters passed in
* @param {String} sNavType type of navigation
*/
onNavigationDone: function(oAppData, oURLParameters, sNavType) {
switch (sNavType) {
case NavType.initial:
break;
case NavType.iAppState:
this._oAppState = oAppData.customData;
// set the previously selected icon filter tab
this.byId("iconTabBar").setSelectedKey(oAppState.selectedTabFilter);
// apply previous filters to table
this._applyFilters();
// set the previous search state
this.byId("searchField").setValue(oAppState.searchText);
// set the previously selected multi combo tokens
this.byId("categories").setSelectedKeys(oAppState.selectedCategories);
this.byId("suppliers").setSelectedKeys(oAppState.selectedSuppliers);
// select previously selected rows
this.byId("table")
.setSelectedContextPaths(oAppState.selectedContextPaths);
break;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |