Skip to Content

Fragment not appearing on page

hello,

I am trying to create a Create/Display form in Fiori wherein I am using two different fragments of create and display on same page. but the fragment does not appear on the execution.

I am using the Fiori SDK for reference

https://sapui5.hana.ondemand.com/#/sample/sap.ui.layout.sample.Form354wide/code

and my fragment name is : create.fragment.xml (in case I'm pointing wrong)

XML

<mvc:View controllerName="com.fiori.specialPrice1.controller.View1" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m"
 xmlns:f="sap.ui.layout.form" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core">
 <Shell id="shell">
  <App id="app" backgroundImage="css/background.jpg">
   <pages>
    <Page id="page" title="{i18n>title}">
     <customHeader>
      <Bar>
       <contentRight>
        <Button id="btnNew" text="New" visible="false" press="handleNewPress"/>
       </contentRight>
      </Bar>
     </customHeader>
     <content></content>
    </Page>
   </pages>
  </App>
 </Shell>
</mvc:View>

JS

sap.ui.define([
 "sap/ui/core/mvc/Controller"
], function (Controller) {
 "use strict";
 return Controller.extend("com.fiori.specialPrice1.controller.View1", {
  onInit: function () {
   // call the create fragment
   this.onChange("create");
  },
  formFragments: {},
  onChange: function (sFragName) {
   var oPage = this.byId("page");
   // place fragment in the page
   oPage.removeAllContent();
   oPage.insertContent(this.getFrag(sFragName));
  },
  getFrag: function (sFragName) {
   var oFormFragment = this.formFragments[sFragName];
   if (oFormFragment) {
    return oFormFragment;
   }
   // get the fragment
   oFormFragment = sap.ui.xmlfragment(this.getView().byId(), "com.fiori.specialPrice1.view.", sFragName);
   this.formFragments[sFragName] = oFormFragment;
   return this.formFragments[sFragName];
  }
 });
});

where have I gone wrong??

thank you

Siddharth

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Mar 12 at 11:46 AM

    Hi,

    https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui/methods/sap.ui.xmlfragment

    the id is not mandatory, so you could try this :

     oFormFragment = sap.ui.xmlfragment("com.fiori.specialPrice1.view." + sFragName,this);

    Regards

    Fabrice

    Add comment
    10|10000 characters needed characters exceeded