3 Replies Latest reply on Feb 18, 2010 8:56 AM by Sebastien V.

    Popup reuse and instantiate data within the popup

    stefideax

      Hi,

       

      I'm trying to implement a popup I can use to edit values via a form. I only pass an ID to the popup. The popup will contact a datasource to load the data from a database, based on the ID, and pre-fill the form. If no ID is passed (or empty), the popup displays an empty form which can be used to add the record to the database.

       

      Based on the samples I found this was quite easy to implement... However, I'm facing a problem in instantiating values, when the popup gets called the first or the second time.

       

      I first added the initialisation code (clearing fields and getting new data from database) in the creationComplete of the popup; but the event does not get fired anymore when opening the popup the second time (popup gets called by PopupManager.addPopup).

       

      I tried triggering the init on the event 'added' or 'addedToStage' as well, but then some of the components in the popup are not yet created the first time I open the popup, giving an exception thrown...

       

      What's the best approach or event to trigger on, to instantiate my data when the popup displays?

       

      Tnx

       

      Stefan

        • 1. Re: Popup reuse and instantiate data within the popup
          Sebastien V.

          If you don't need to keep working on the same instance of your pop up you could use the creationComplete event and pop different instances every time, with PopUpManager.createPopUp() and PopUpManager.closePopUp().

           

          If you need to keep working on the same instance, you could use a setter for the ID you pass to the pop up, and trigger the data instanciation in it.

          1 person found this helpful
          • 2. Re: Popup reuse and instantiate data within the popup
            stefideax Level 1

            Thanks, I found where I went wrong... the removePopUp was porperly called from my code; I tried a createPopUp, but stored it in a local value, and reused it... Now I realy use a new instance and it works on the creationComplete...

             

            However, if I would like to use the same instance, and add it with 'addPopUp', should I still remove it?, and on which event I can best trigger the instantiation : I would like to instantiate the values when the popup is displayed, I don't want to add a button 'update the data'...?

            • 3. Re: Popup reuse and instantiate data within the popup
              Sebastien V. Level 3

              I'm not familiar with the pop up events, but maybe the show event could do it (not sure if it's dispatched for pop ups though).

               

              If there's no event just do it manually (and not with a button). Create a method instantiate() in your pop up, and call it just after the PopUpManager.addPopUp() call.