cancel
Showing results for 
Search instead for 
Did you mean: 

Problem seting model to SelectDialog

al_sapui5
Participant
0 Kudos

I'm triying to figure out whay my data is not displayed in my selectDialog

this is my view:

<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:core="sap.ui.core">
    <SelectDialog
        id="patronDialogo"
        noDataText="Sin patrones"
        title="Seleccione un patr/u00F4"
        search=".onSearch"
        confirm=".onDialogClose"
        cancel=".onDialogClose"
        items="{patrones>/}">
        <StandardListItem
            title="{patrones>DescripcionCont}"
            description="{patrones>TipoContenedor}"
            icon="sap-icon://shipping-status"
            iconDensityAware="false"
            iconInset="false"
            type="Active" />
    </SelectDialog>
</core:FragmentDefinition>

and this is my controller:

var url = "/sap/opu/odata/sap/ZCLMMVSR_ODATA_CARGA_CONTENT_SRV";
            var oDataModel = new sap.ui.model.odata.ODataModel(url, true);
            var mensaje = "";
            var oView = this.getView();
            var jsonData = new JSONModel();
            sap.ui.core.BusyIndicator.show(0);

            if ( !this._oDialogPatron ) {
                this._oDialogPatron = sap.ui.xmlfragment("z_vsr_ihu_cargarContenedor.view.DialogPatron", this);
            }

            try {
                oDataModel.read("/patronFotosSet", {
                    success: function(oData, response) {
                        sap.ui.core.BusyIndicator.hide();
                        jsonData.setData(oData.results);
                        oView.setModel(jsonData, "patrones");                   
                    },
                    error: function(oError) {
                        sap.ui.core.BusyIndicator.hide();
                    }
                });
            } catch (e){
                sap.ui.core.BusyIndicator.hide();
                return reject(mensaje = "ERROR en llamado OData")
            }

            jQuery.sap.syncStyleClass("sapUiSizeCompact", this.getView(), this._oDialogPatron);
            this.getView().addDependent(this._oDialogPatron);
            this._oDialogPatron.open();

So my select dialog it's displayed but whithout data:

Accepted Solutions (1)

Accepted Solutions (1)

FlorianAlbrecht
Discoverer
0 Kudos

Hi,

I think the problem here is due to the async nature of your oData call. While you instantiate the dialog and open it, the async oData call is triggered to load the data and to set the model. So you have to make sure, that the model data is loaded first before you instatiate the dialog.

I tried it the following way and it works perfectly:

Dialog code:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
  <SelectDialog id="selectDialog" noDataText="No data" 
   title="Test select" 
   search=".onSearch" 
   confirm=".onDialogClose" 
   cancel=".onDialogClose"
   items="{patrones>/}">

<StandardListItem 
 title="{patrones>DescripcionCont}" 
 description="{patrones>TipoContenedor}" 
 icon="sap-icon://shipping-status"
 iconDensityAware="false" 
 iconInset="false" type="Active"/>
</SelectDialog>

</core:FragmentDefinition>

Controller code:

fnOnSelectDialogShow: function () {
  var jsonModel = new JSONModel();
  var oModel = this.getView().getModel();


  oModel.read("/patronFotosSet", {
    success: function (oData) {
	jsonModel.setData(oData.results);
	this.getView().setModel(jsonModel, "patrones");


	// Load Dialog
	if (!this._oDialog) {
	  Fragment.load({
	    name: "z_vsr_ihu_cargarContenedor.view.DialogPatron",
            controller: this
	}).then(function (oDialog) {
	  this._oDialog = oDialog;
	  this.getView().addDependent(this._oDialog);
	  this._oDialog.open();
	 }.bind(this);
	} else {
          this._oDialog.open();
	}.bind(this)
	},
	error: function (oError) {
	  MessageToast.show("Error occured");
	}
});
}
al_sapui5
Participant
0 Kudos

i have 1.52.18 version so i cant use fragmen.load :c

FlorianAlbrecht
Discoverer
0 Kudos

Just use your old syntax then. It's just important to sync the oData call with the instantiation of your dialog.

So in the success handler call sap.ui.xmlfragment().

Answers (0)