on 02-12-2019 9:52 AM
(Hellodialog.xml).....fregment file
<core:FragmentDefinition
xmlns="sap.m" xmlns:core="sap.ui.core">
<Dialog id="helloDialog"
tittle="Hello {/recipient/name}">
</Dialog>
</core:FragmentDefinition>
----------------------------------------------------------------------------------------
HelloPanel.view,xml....Xml View code
<mvc:View
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
controllerName="demo1.Fregments.controller.HelloPanel"
xmlns:html="http://www.w3.org/1999/xhtml">
<Panel
headerText="{i18n>helloPanelText}"
width="auto">
<content>
<Button
text="{i18n>ButtonShowPanel}"
class="sapUiResponsiveMarginEnd"
press="onShowHello"/>
<Input
value="{/recipient/name}"
valueLiveUpdate="true"
width="60%"/>
<Button
text="{i18n>ButtonShowDialog}"
id="helloButtonPanel"
press="onShowDialog"
class="sapUiResponsiveMarginEnd"/>
</content>
</Panel>
</mvc:View>
-----------------------------------------------------------------------------------------
HelloPanel.controller.js ..file
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"sap/ui/core/Fragment" ],
function (Controller, MessageToast, Fragment){
"use strict";
return Controller.extend("demo1.Fregments.controller.HelloPanel", {
onInit: function () {
},
onShowHello: function () {
var oBundle = this.getView().getModel("i18n").getResourceBundle();
var sRecipient = this.getView().getModel().getProperty("/recipient/name");
var sMsg = oBundle.getText("helloMsg", [sRecipient]);
MessageToast.show(sMsg);
},
onOpenDialog: function () {
var oView = this.getView();
// create dialog lazily
if (!this.byId("helloDialog"))
{
// load asynchronous XML fragment
Fragment.load({
id: oView.getId(),
name: " demo1.Fregments.view.Hellodialog "
}).then(function (oDialog) {
// connect dialog to the root view of this component
oView.addDependent(oDialog);
oDialog.open();
});
} else {
this.byId("helloDialog").open();
} }
});
});
---------------------------------------------------------------------------------
Component.js file...
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device", "demo1/Fregments/model/models" ],
function (UIComponent, Device, models) {
"use strict";
return UIComponent.extend("demo1.Fregments.Component", {
metadata: {
manifest: "json"
},
init: function () {
UIComponent.prototype.init.apply(this, arguments);
var oData = {
recipient: {
name: "World"}
};
var oModel = new sap.ui.model.json.JSONModel(oData);
this.setModel(oModel); this.getRouter().initialize();
this.setModel(models.createDeviceModel(), "device");
} });
});
Hello,
one observation is that the function to open Dialog fragment is named as onOpenDialog inside HelloPanel Controller, while inside the HelloPanel view you are calling an undefined function onShowDialog.
Thanks & Kind Regards,
Bopanna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.