Skip to Content
0
Former Member
Jul 05, 2016 at 01:19 PM

Binding JSON model to Dialog

4034 Views

Hi all,

I have a problem trying to set a BindingContext from a JSON model to my dialog control.

I have already successfully used a BindingContext from an OData model to this control setup, but need to get it working from a JSON model for a create operation.

Upon my event trigger, I create a new JSON model, set the model to the View, add the Dialog control as a dependent of the View so it has access to view models, and finally I set the bindingContext of the Dialog control to my new JSON model. But no values from my JSON model appear. Values from another view JSON model appear (with absolute paths), but the relative paths show empty.

Note my dialog is composed of two fragments, a generic container that is the dialog control, and then contents of the dialog - an edit fragment (I also have a view fragment).

Thanks in advance for any help, if someone has done this before.

Jason

JS:

onAddEventPress: function(oEvent) {
            var oDialog = sap.ui.xmlfragment("mynamespace.view.fragment.AppDialog", this);  //generic dialog fragment
            
            var oModel = new JSONModel({
                EventCode: "TRACKING",
                EventDateTime: new Date()
            });
            this.getView().setModel(oModel, "event");
   
            this.getView().addDependent(oDialog);
      
            //Dialog contents fragment
            var oLayout = sap.ui.getCore().byId("gridDialog"),
                oFragment = sap.ui.xmlfragment("freightexecution.view.fragment.EMEdit", this);
            oLayout.addContent(oFragment);
            
            oDialog.setBindingContext(new sap.ui.model.Context(
                this.getView().getModel("event"), 
                "/" 
            ));
            
            oDialog.open();
        },

Dialog Container XML fragment:

<Dialog 
    id="dlgApp"
    xmlns:c="sap.ui.core" 
    xmlns:l="sap.ui.layout" 
    xmlns="sap.m">
    <content>
        <l:Grid id="gridDialog" defaultSpan="L12 M12 S12" hSpacing="0" />
    </content>
    <endButton>
        <Button icon="sap-icon://add" text="{i18n>emDialog.SaveEM}" press="onEMSavePress" type="Emphasized" />
    </endButton>
</Dialog>

Dialog Contents XML fragment:

<c:FragmentDefinition
  xmlns="sap.m"
  xmlns:l="sap.ui.layout" 
  xmlns:f="sap.ui.layout.form"
  xmlns:c="sap.ui.core">
    <f:SimpleForm id="frmEvent" editable="true" hSpacing="0" vSpacing="0" maxContainerCols="2" layout="ResponsiveGridLayout">
        <f:content>
            <Text text="working? {EventCode}"><!--This should say 'TRACKING', but it's empty-->
                <layoutData>
                    <l:GridData span="L12 M12 S12" />
                </layoutData>
            </Text>
            <Text text="{path:'local>/DateTimeTicker', formatter:'.formatter.dateTimeDetailString'}">
                <layoutData>
                    <l:GridData span="L12 M12 S12" />
                </layoutData>
            </Text>

        </f:content>
    </f:SimpleForm>
</c:FragmentDefinition>