In this example, the personalization data is a set of flags set by the user and then explicitly saved.
We need the following steps in our application:
Application initialization:
Get the personalizer.
React on the Save button.
Write the personalization data.
There is one personalizer per item. Technically, each item is part of a container. So a personalizer is identified by the container and the item.
oPersonalizationService = sap.ushell.Container.getService("Personalization"); oComponent = sap.ui.core.Component.getOwnerComponentFor(this.getView()); oScope = { keyCategory : oPersonalizationService.constants.keyCategory.FIXED_KEY, writeFrequency: oPersonalizationService.constants.writeFrequency.LOW, clientStorageAllowed : true }; ... oPersId = { container : "sap.ushell.samples.persSample1", item : "fruits" }; ... oPersonalizer = oPersonalizationService.getPersonalizer(oPersId, oScope, oComponent);
The getPersData method is asynchronous and uses the deferred object functionality (jQuery.Deferred).
oReadPromise = oPersonalizer.getPersData() .done(function(oPersData){ // Pseudo code: set the checkboxes on the UI according to the read personalization data }) .fail(function() { jQuery.sap.log.error(“Reading personalization data failed.”) });
The save method is asynchronous as well.
oSavePromise = this.oPersonalizer.setPersData(oPersData) .done(function(){ // Tell the user that the data was saved }) .fail(function() { jQuery.sap.log.error(“Writing personalization data failed.”) });
The personalization service ensures that the save and load operations to the front-end server are sequentialized, so that a subsequent operation is only started when the previous one is finished.