cancel
Showing results for 
Search instead for 
Did you mean: 

Dialog Screen is working on first time but not at all time.

Former Member
0 Kudos

Hello expert,

While I'm developing my project I add a button which is calling a dialog screen but on first time its working perfect. But If I want to press the button one more time there is a error like this: "Uncaught Error: The object with ID pddepLayout1 was destroyed and cannot be used anymore."

Please help this situation.

Here is my all code :


var opddepButton1 = new sap.m.Button('opddepButton1',{text:'Ekle',

  press:function(oEvent){

  oDialog.setBindingContext(oEvent.oSource

            .getBindingContext());

  openDialog();

    }

   

    });

                

               

  function openDialog() {

       oDialog.destroyContent();

  

    var opddepButton = new sap.m.Button('opddepButton',{text:'Ekle',press:function(){

    

    

            var fname = sap.ui.getCore().byId('pdmalkod').getValue();

            var lname = sap.ui.getCore().byId('pdparti').getValue();

            var aname = sap.ui.getCore().byId('pdmiktar').getValue();

            var bname = sap.ui.getCore().byId('pdolcbir').getValue();

            var cname = sap.ui.getCore().byId('pdmasyer').getValue();

            var dname = sap.ui.getCore().byId('pdnedekod').getValue();

           

            mdData.clients.push({"id":fname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname });

            oModel.setData(mdData);

           

            oDialog.close();

           

           

           

           

            }

           

            });

    var labelidmalkod = new sap.m.Label('labelidmalkod',{text:'Malzeme Kodu:'

           

        });

        var pdmalkod = new sap.m.Input('pdmalkod',{

       

        });

       var labelidparti = new sap.m.Label('labelidparti',{text:'Parti:'

       

        });

       var pdparti = new sap.m.Input('pdparti',{

       

        });

      

       var labelidmiktar = new sap.m.Label('labelidmiktar',{text:'Miktar:'

          

       });

      var pdmiktar = new sap.m.Input('pdmiktar',{

      

       });

     

      var labelidolcbir = new sap.m.Label('labelidolcbir',{text:'Ölçü Birimi:'

       

      });

     var pdolcbir = new sap.m.Input('pdolcbir',{

     

      });

    

     var labelidmasyer = new sap.m.Label('labelidmasyer',{text:'Masraf Yeri:'

       

     });

    var pdmasyer = new sap.m.Input('pdmasyer',{

    

     });

    

    var labelidnedkod = new sap.m.Label('labelidnedkod',{text:'Neden Kodu:'

       

    });

    var pdnedekod = new sap.m.Input('pdnedekod',{

    

    });

      

     pddepLayout1.createRow(labelidmalkod, pdmalkod);

      

     pddepLayout1.createRow(labelidparti, pdparti);

    

     pddepLayout1.createRow(labelidmiktar, pdmiktar);

    

     pddepLayout1.createRow(labelidolcbir, pdolcbir);

    

     pddepLayout1.createRow(labelidmasyer, pdmasyer);

    

     pddepLayout1.createRow(labelidnedkod, pdnedekod);

     pddepLayout1.createRow(opddepButton);

    

     oDialog.addContent(pddepLayout1);

    

    

    

     oDialog.open();

  

    };

Thanks,

Ogulcan G.

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,


I guess pddepLayout1 is a Matrix Layout. You are adding this layout to a dialog content.


Instead of destroying content, why don't you use .removeAllRows() method of Matrix Layout. Something like this -


function openDialog() { 

       var oLayout = sap.ui.getCore().byId("pddepLayout1");          //Get Hold of Matrix Layout

    oLayout.removeAllRows();               //Remove all Rows of Matrix Layout

    //and then your code

}

Regards,

Sai Vellanki.


Former Member
0 Kudos

Hi Sai,

Firstly, yes it is a Matrix Layout.

I tried this solution but right now this error was shown:

"Cannot read property 'removeAllRows' of undefined"

Isn't it a function of MatrixLayout? Why this error was taken to me couldnt understand it.

Thank you,

Ogulcan G.

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

Where are you creating the Matrix Layout with id 'pddepLayout1' ? Also can you try something like this as well? 


function openDialog() { 

       var oLayout = sap.ui.getCore().byId("pddepLayout1");      //Matrix Layout

    if(oLayout){                         //If Matrix Layout with id pddepLayout1 exists

    oLayout.removeAllRows();      //Remove Rows

    }

    //and then your code

}

Yes, there is a method .removeAllRows(). Here is the API: JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.commons.layout.MatrixLa...

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Sai,

Do I need delete this code also on the beginning which creating pddepLayout1?

createContent : function(oController) {

  "mobiletestproject.pddepgel202".viewName = "wwwwwwwwwwwww";

  var pddepLayout = new sap.ui.commons.layout.MatrixLayout('pddepLayout');

        pddepLayout.setWidth('100%');

      

        var pddepLayout1 = new sap.ui.commons.layout.MatrixLayout('pddepLayout1');

        pddepLayout1.setWidth('100%');

Former Member
0 Kudos

And also this error was taken :

"The object with ID pddepLayout1 was destroyed and cannot be used anymore."

Still is not working

saivellanki
Active Contributor
0 Kudos

Ogulcan,

Check this sample, which is bit similar to your requirement: Plunker

Click on Edit, you will get the details of row and when you're closing the dialog, it just says sap.ui.getCore().byId("yourDialogID").destroy();

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Sai,

Thank you for your helps right now it works!

Regards,

Ogulcan G.

Answers (1)

Answers (1)

sebastianraemsch
Active Participant
0 Kudos

Hi Ogulcan,

I think it´s because you "destroy the content" (line 12 in your code snippet) of the dialog when open it. At first time pddepLayout1 is not part of the content. So it works. After first call pddepLayout1 is part of the content as you added it in line 89. So it will be destroyed and afterwards you can´t use it anymore. So I don´t know what´s the best approach in your case but maybe you should consider only destroying the content of pddepLayout1 and not the content of the complete dialog.

Best regards,

Sebastian

Former Member
0 Kudos

Hi Sebastian,

Yeah I agree with you but I still couldn't fix my problem even try change where defination of pddepLayout1 and also change type of layout (for ex. border). I'm trying also right now another solutions but doesnt work for me.

Thank you for answering,

Ogulcan G.